Cataclysm BN
game Class Reference

#include <game.h>

Classes

class  Creature_range
 
class  debug_hour_timer
 
class  draw_callback_t
 
class  monster_range
 
class  non_dead_range
 
class  npc_range
 

Public Member Functions

 game ()
 
 ~game ()
 
void load_static_data ()
 Loads static data that does not depend on mods or similar. More...
 
std::string get_player_base_save_path () const
 Base path for saving player data. More...
 
std::string get_world_base_save_path () const
 Base path for saving world data. More...
 
void on_options_changed ()
 Should be invoked whenever options change. More...
 
void setup ()
 
void serialize (std::ostream &fout)
 Saving and loading functions. More...
 
void unserialize (std::istream &fin)
 
void unserialize_master (std::istream &fin)
 
bool dump_stats (const std::string &what, dump_mode mode, const std::vector< std::string > &opts)
 write statistics to stdout and More...
 
bool save ()
 Returns false if saving failed. More...
 
std::vector< std::string > list_active_saves ()
 Returns a list of currently active character saves. More...
 
void write_memorial_file (const std::string &filename, std::string sLastWords)
 Writes information about the character out to a text file timestamped with the time of the file was made. More...
 
bool cleanup_at_end ()
 
void start_calendar ()
 
bool do_turn ()
 MAIN GAME LOOP. More...
 
shared_ptr_fast< ui_adaptorcreate_or_get_main_ui_adaptor ()
 
void invalidate_main_ui_adaptor () const
 
void mark_main_ui_adaptor_resize () const
 
void draw ()
 
void draw_ter (bool draw_sounds=true)
 
void draw_ter (const tripoint &center, bool looking=false, bool draw_sounds=true)
 
void add_draw_callback (shared_ptr_fast< draw_callback_t > cb)
 
void draw_panels (bool force_draw=false)
 
std::optional< tripointget_veh_dir_indicator_location (bool next) const
 Returns the location where the indicator should go relative to the reality bubble, or nothing to indicate no indicator should be drawn. More...
 
void draw_veh_dir_indicator (bool next)
 
void vertical_move (int z, bool force, bool peeking=false)
 Moves the player vertically. More...
 
void start_hauling (const tripoint &pos)
 
std::optional< tripointfind_or_make_stairs (map &mp, int z_after, bool &rope_ladder, bool peeking)
 Returns the other end of the stairs (if any). More...
 
void vertical_shift (int z_after)
 Actual z-level movement part of vertical_move. More...
 
void vertical_notes (int z_before, int z_after)
 Add goes up/down auto_notes (if turned on) More...
 
void use_computer (const tripoint &p)
 Checks to see if a player can use a computer (not illiterate, etc.) and uses if able. More...
 
template<typename T = Creature>
T * critter_by_id (const character_id &id)
 
template<typename T = Creature>
T * critter_at (const tripoint &p, bool allow_hallucination=false)
 Returns the Creature at the given location. More...
 
template<typename T = Creature>
const T * critter_at (const tripoint &p, bool allow_hallucination=false) const
 
template<typename T = Creature>
shared_ptr_fast< T > shared_from (const T &critter)
 Returns a shared pointer to the given critter (which can be of any of the subclasses of Creature). More...
 
size_t num_creatures () const
 Returns the approximate number of creatures in the reality bubble. More...
 
bool update_zombie_pos (const monster &critter, const tripoint &pos)
 Redirects to the creature_tracker update_pos() function. More...
 
void remove_zombie (const monster &critter)
 
void clear_zombies ()
 Redirects to the creature_tracker clear() function. More...
 
bool spawn_hallucination (const tripoint &p)
 Spawns a hallucination at a determined position. More...
 
bool swap_critters (Creature &, Creature &)
 Swaps positions of two creatures. More...
 
Creature_range all_creatures ()
 Returns an anonymous range that contains all creatures. More...
 
monster_range all_monsters ()
 Same as all_creatures but iterators only over monsters. More...
 
npc_range all_npcs ()
 Same as all_creatures but iterators only over npcs. More...
 
std::vector< Creature * > get_creatures_if (const std::function< bool(const Creature &)> &pred)
 Returns all creatures matching a predicate. More...
 
std::vector< npc * > get_npcs_if (const std::function< bool(const npc &)> &pred)
 
Creatureget_creature_if (const std::function< bool(const Creature &)> &pred)
 Returns a creature matching a predicate. More...
 
bool is_empty (const tripoint &p)
 Returns true if there is no player, NPC, or monster on the tile and move_cost > 0. More...
 
bool is_in_sunlight (const tripoint &p)
 Returns true if p is outdoors and it is sunny. More...
 
bool is_sheltered (const tripoint &p)
 Returns true if p is indoors, underground, or in a car. More...
 
bool revive_corpse (const tripoint &p, item &it)
 Revives a corpse at given location. More...
 
void save_cyborg (item *cyborg, const tripoint &couch_pos, player &installer)
 Turns Broken Cyborg monster into Cyborg NPC via surgery. More...
 
bool cancel_activity_query (const std::string &text)
 Asks if the player wants to cancel their activity, and if so cancels it. More...
 
bool cancel_activity_or_ignore_query (distraction_type type, const std::string &text)
 Asks if the player wants to cancel their activity and if so cancels it. More...
 
void moving_vehicle_dismount (const tripoint &dest_loc)
 Handles players exiting from moving vehicles. More...
 
vehicleremoteveh ()
 Returns the current remotely controlled vehicle. More...
 
void setremoteveh (vehicle *veh)
 Sets the current remotely controlled vehicle. More...
 
int assign_mission_id ()
 Returns the next available mission id. More...
 
npcfind_npc (character_id id)
 Find the npc with the given ID. More...
 
void load_npcs ()
 Makes any nearby NPCs on the overmap active. More...
 
void reload_npcs ()
 Unloads, then loads the NPCs. More...
 
void add_npc_follower (const character_id &id)
 Add follower id to set of followers. More...
 
void remove_npc_follower (const character_id &id)
 Remove follower id from follower set. More...
 
std::set< character_idget_follower_list ()
 Get set of followers. More...
 
void validate_npc_followers ()
 validate list of followers to account for overmap buffers More...
 
void validate_mounted_npcs ()
 
void validate_linked_vehicles ()
 validate towed vehicles so they get linked up again after a load More...
 
void validate_camps ()
 validate camps to ensure they are on the overmap list More...
 
void autopilot_vehicles ()
 process vehicles that are following the player More...
 
void catch_a_monster (monster *fish, const tripoint &pos, player *p, const time_duration &catch_duration)
 Picks and spawns a random fish from the remaining fish list when a fish is caught. More...
 
std::unordered_set< tripointget_fishable_locations (int distance, const tripoint &fish_pos)
 Get the contiguous fishable locations starting at fish_pos, out to the specificed distance. More...
 
std::vector< monster * > get_fishable_monsters (std::unordered_set< tripoint > &fishable_locations)
 Get the fishable monsters within the provided fishable locations. More...
 
void fling_creature (Creature *c, const units::angle &dir, float flvel, bool controlled=false)
 Flings the input creature in the given direction. More...
 
float natural_light_level (int zlev) const
 
unsigned char light_level (int zlev) const
 Returns coarse number-of-squares of visibility at the current light level. More...
 
void reset_light_level ()
 
character_id assign_npc_id ()
 
Creatureis_hostile_nearby ()
 
Creatureis_hostile_very_close ()
 
point update_map (player &p)
 
point update_map (int &x, int &y)
 
void update_overmap_seen ()
 
void process_artifact (item &it, player &p)
 
void add_artifact_messages (const std::vector< art_effect_passive > &effects)
 
void add_artifact_dreams ()
 
void peek ()
 
void peek (const tripoint &p)
 
std::optional< tripointlook_debug ()
 
bool check_zone (const zone_type_id &type, const tripoint &where) const
 
bool check_near_zone (const zone_type_id &type, const tripoint &where) const
 Checks whether or not there is a zone of particular type nearby. More...
 
bool is_zones_manager_open () const
 
void zones_manager ()
 
std::optional< tripointlook_around (bool force_3d=false)
 
look_around_result look_around (bool show_window, tripoint &center, const tripoint &start_point, bool has_first_point, bool select_zone, bool peeking, bool is_moving_zone=false, const tripoint &end_point=tripoint_zero, bool force_3d=false)
 
void pre_print_all_tile_info (const tripoint &lp, const catacurses::window &w_info, int &line, int last_line, const visibility_variables &cache)
 
void print_all_tile_info (const tripoint &lp, const catacurses::window &w_look, const std::string &area_name, int column, int &line, int last_line, const visibility_variables &cache)
 
void draw_look_around_cursor (const tripoint &lp, const visibility_variables &cache)
 
void extended_description (const tripoint &p)
 Long description of (visible) things at tile. More...
 
void draw_trail_to_square (const tripoint &t, bool bDrawX)
 
item_location inv_map_splice (item_filter filter, const std::string &title, int radius=0, const std::string &none_message="")
 Custom-filtered menu for inventory and nearby items and those that within specified radius. More...
 
bool has_gametype () const
 
special_game_type gametype () const
 
void toggle_fullscreen ()
 
void toggle_pixel_minimap ()
 
void reload_tileset (std::function< void(std::string)> out)
 
void temp_exit_fullscreen ()
 
void reenter_fullscreen ()
 
void zoom_in ()
 
void zoom_out ()
 
void reset_zoom ()
 
void set_zoom (int level)
 
int get_zoom () const
 
int get_moves_since_last_save () const
 
int get_user_action_counter () const
 
bool take_screenshot (const std::string &file_path) const
 Saves a screenshot of the current viewport, as a PNG file, to the given location. More...
 
bool take_screenshot () const
 Saves a screenshot of the current viewport, as a PNG file. More...
 
int get_levx () const
 The top left corner of the reality bubble (in submaps coordinates). More...
 
int get_levy () const
 
int get_levz () const
 
void load_map (const tripoint &pos_sm, bool pump_events=false)
 Load the main map at given location, see map::load, in global, absolute submap coordinates. More...
 
void load_map (const tripoint_abs_sm &pos_sm, bool pump_events=false)
 
overmapget_cur_om () const
 The overmap which contains the center submap of the reality bubble. More...
 
std::vector< npc * > allies ()
 Get all living player allies. More...
 
void set_driving_view_offset (point p)
 
void calc_driving_offset (vehicle *veh=nullptr)
 
void toggle_gate (const tripoint &p)
 
void knockback (const tripoint &s, const tripoint &t, int force, int stun, int dam_mult, Creature *source)
 
void knockback (std::vector< tripoint > &traj, int stun, int dam_mult, Creature *source)
 
void draw_bullet (const tripoint &t, int i, const std::vector< tripoint > &trajectory, char bullet)
 
void draw_hit_mon (const tripoint &p, const monster &m, bool dead=false)
 
void draw_hit_player (const Character &p, int dam)
 
void draw_line (const tripoint &p, const tripoint &center_point, const std::vector< tripoint > &points, bool noreveal=false)
 
void draw_line (const tripoint &p, const std::vector< tripoint > &points)
 
void draw_weather (const weather_printable &wPrint)
 
void draw_sct ()
 
void draw_zones (const tripoint &start, const tripoint &end, const tripoint &offset)
 
void draw_critter (const Creature &critter, const tripoint &center)
 
void draw_critter_highlighted (const Creature &critter, const tripoint &center)
 
void draw_cursor (const tripoint &p)
 
void draw_highlight (const tripoint &p)
 
void draw_radiation_override (const tripoint &p, int rad)
 
void draw_terrain_override (const tripoint &p, const ter_id &id)
 
void draw_furniture_override (const tripoint &p, const furn_id &id)
 
void draw_graffiti_override (const tripoint &p, bool has)
 
void draw_trap_override (const tripoint &p, const trap_id &id)
 
void draw_field_override (const tripoint &p, const field_type_id &id)
 
void draw_item_override (const tripoint &p, const itype_id &id, const mtype_id &mid, bool hilite)
 
void draw_vpart_override (const tripoint &p, const vpart_id &id, int part_mod, units::angle veh_dir, bool hilite, point mount)
 
void draw_below_override (const tripoint &p, bool draw)
 
void draw_monster_override (const tripoint &p, const mtype_id &id, int count, bool more, Creature::Attitude att)
 
bool is_in_viewport (const tripoint &p, int margin=0) const
 
bool check_safe_mode_allowed (bool repeat_safe_mode_warnings=true)
 Check whether movement is allowed according to safe mode settings. More...
 
void set_safe_mode (safe_mode_type mode)
 
void exam_vehicle (vehicle &veh, point cp=point_zero)
 open vehicle interaction screen More...
 
bool forced_door_closing (const tripoint &p, const ter_id &door_type, int bash_dmg)
 
bool load (const std::string &world)
 Attempt to load first valid save (if any) in world. More...
 
bool npc_menu (npc &who)
 Returns true if the menu handled stuff and player shouldn't do anything else. More...
 
bool phasing_move (const tripoint &dest, bool via_ramp=false)
 
bool walk_move (const tripoint &dest, bool via_ramp=false)
 
void on_move_effects ()
 
point place_player (const tripoint &dest)
 
void place_player_overmap (const tripoint_abs_omt &om_dest)
 
unsigned int get_seed () const
 
void set_npcs_dirty ()
 If invoked, NPCs will be reloaded before next turn. More...
 
void set_critter_died ()
 If invoked, dead will be cleaned this turn. More...
 
void mon_info (const catacurses::window &, int hor_padding=0)
 
void mon_info_update ()
 
void cleanup_dead ()
 
bool is_dangerous_tile (const tripoint &dest_loc) const
 
std::vector< std::string > get_dangerous_tile (const tripoint &dest_loc) const
 
bool prompt_dangerous_tile (const tripoint &dest_loc) const
 
void despawn_monster (monster &critter)
 Despawn a specific monster, it's stored on the overmap. More...
 
void win ()
 Marks the game as won. More...
 
bool disable_robot (const tripoint &p)
 If there is a robot (that can be disabled), query the player and try to disable it. More...
 
void draw_pixel_minimap (const catacurses::window &w)
 
void quicksave ()
 
void disp_NPCs ()
 
void list_missions ()
 
event_busevents ()
 
stats_trackerstats ()
 
kill_trackerget_kill_tracker ()
 
memorial_loggermemorial ()
 
spell_eventsspell_events_subscriber ()
 
void display_toggle_overlay (action_id)
 
bool display_overlay_state (action_id)
 
void toggle_debug_hour_timer ()
 
tripoint mouse_edge_scrolling_terrain (input_context &ctxt)
 Used to implement mouse "edge scrolling". More...
 
tripoint mouse_edge_scrolling_overmap (input_context &ctxt)
 This variant is suitable for the overmap. More...
 
void shift_destination_preview (point delta)
 
bool slip_down ()
 Checks if player is able to successfully climb to/from some terrain and not slip down. More...
 
monsterplace_critter_at (const mtype_id &id, const tripoint &p)
 Adds critters to the reality bubble, creating them if necessary. More...
 
monsterplace_critter_at (const shared_ptr_fast< monster > &mon, const tripoint &p)
 
monsterplace_critter_around (const mtype_id &id, const tripoint &center, int radius)
 
monsterplace_critter_around (const shared_ptr_fast< monster > &mon, const tripoint &center, int radius, bool forced=false)
 
monsterplace_critter_within (const mtype_id &id, const tripoint_range< tripoint > &range)
 
monsterplace_critter_within (const shared_ptr_fast< monster > &mon, const tripoint_range< tripoint > &range)
 

Public Attributes

mapm
 
avataru
 
scent_mapscent
 
timed_event_managertimed_events
 
pimpl< Creature_trackercritter_tracker
 
pimpl< faction_managerfaction_manager_ptr
 
pimpl< drop_token_providertoken_provider_ptr
 
quit_status uquit
 Used in main.cpp to determine what type of quit is being performed. More...
 
bool new_game = false
 True if the game has just started or loaded, else false. More...
 
const scenarioscen = nullptr
 
std::vector< monstercoming_to_stairs
 
int monstairz = 0
 
tripoint ter_view_p
 
catacurses::window w_terrain
 
catacurses::window w_overmap
 
catacurses::window w_omlegend
 
catacurses::window w_minimap
 
catacurses::window w_pixel_minimap
 
point driving_view_offset
 
bool debug_pathfinding = false
 
bool debug_submap_grid_overlay = false
 
Creaturedisplaying_visibility_creature
 Creature for which to display the visibility map. More...
 
int displaying_lighting_condition = 0
 Type of lighting condition overlay to display. More...
 
bool show_panel_adm = false
 
bool right_sidebar = false
 
bool fullscreen = false
 
bool was_fullscreen = false
 
bool auto_travel_mode = false
 
bool queue_screenshot = false
 
safe_mode_type safe_mode
 
int turnssincelastmon = 0
 
int mostseen = 0
 

Private Types

enum class  vmenu_ret : int { CHANGE_TAB , QUIT , FIRE }
 

Private Member Functions

void unload_npcs ()
 Unloads all NPCs. More...
 
bool load (const save_t &name)
 
void load_master ()
 
bool start_game ()
 
bool save_factions_missions_npcs ()
 
void reset_npc_dispositions ()
 
void serialize_master (std::ostream &fout)
 
bool save_artifacts ()
 
bool save_maps ()
 
void init_autosave ()
 
void create_starting_npcs ()
 
vehicleplace_vehicle_nearby (const vproto_id &id, const point_abs_omt &origin, int min_distance, int max_distance, const std::vector< std::string > &omt_search_types={})
 
void list_items_monsters ()
 
game::vmenu_ret list_items (const std::vector< map_item_stack > &item_list)
 
std::vector< map_item_stackfind_nearby_items (int iRadius)
 
void reset_item_list_state (const catacurses::window &window, int height, bool bRadiusSort)
 
game::vmenu_ret list_monsters (const std::vector< Creature * > &monster_list)
 
bool grabbed_move (const tripoint &dp)
 Check for dangerous stuff at dest_loc, return false if the player decides not to step there. More...
 
bool grabbed_veh_move (const tripoint &dp)
 
bool grabbed_furn_move (const tripoint &dp)
 
void control_vehicle ()
 
void examine (const tripoint &p)
 
void examine ()
 
void pickup ()
 
void pickup (const tripoint &p)
 
void pickup_feet ()
 
void drop ()
 
void drop_in_direction ()
 
void butcher ()
 
void chat ()
 
void print_fields_info (const tripoint &lp, const catacurses::window &w_look, int column, int &line)
 
void print_terrain_info (const tripoint &lp, const catacurses::window &w_look, const std::string &area_name, int column, int &line)
 
void print_trap_info (const tripoint &lp, const catacurses::window &w_look, int column, int &line)
 
void print_creature_info (const Creature *creature, const catacurses::window &w_look, int column, int &line, int last_line)
 
void print_vehicle_info (const vehicle *veh, int veh_part, const catacurses::window &w_look, int column, int &line, int last_line)
 
void print_visibility_info (const catacurses::window &w_look, int column, int &line, visibility_type visibility)
 
void print_items_info (const tripoint &lp, const catacurses::window &w_look, int column, int &line, int last_line)
 
void print_graffiti_info (const tripoint &lp, const catacurses::window &w_look, int column, int &line, int last_line)
 
input_context get_player_input (std::string &action)
 
void replace_stair_monsters ()
 
void update_stair_monsters ()
 
void shift_monsters (const tripoint &shift)
 Shift all active monsters, the shift vector is the number of shifted submaps. More...
 
void perhaps_add_random_npc ()
 
void monmove ()
 
void overmap_npc_move ()
 
void process_voluntary_act_interrupt ()
 
void process_activity ()
 
void handle_key_blocking_activity ()
 
void open_consume_item_menu ()
 
bool handle_action ()
 
bool try_get_right_click_action (action_id &act, const tripoint &mouse_target)
 
bool try_get_left_click_action (action_id &act, const tripoint &mouse_target)
 
void item_action_menu ()
 
bool is_game_over ()
 
void death_screen ()
 
void win_screen ()
 
void draw_minimap ()
 
void autosave ()
 
void quickload ()
 
bool handle_mouseview (input_context &ctxt, std::string &action)
 
void display_faction_epilogues ()
 
void disp_NPC_epilogues ()
 
void display_scent ()
 
void display_temperature ()
 
void display_vehicle_ai ()
 
void display_visibility ()
 
void display_lighting ()
 
void display_radiation ()
 
void display_transparency ()
 
Creatureis_hostile_within (int distance)
 
void move_save_to_graveyard (const std::string &dirname)
 
bool save_player_data ()
 
std::pair< tripoint, tripointmouse_edge_scrolling (input_context &ctxt, int speed, const tripoint &last, bool iso)
 

Private Attributes

bool is_looking = false
 
std::vector< weak_ptr_fast< draw_callback_t > > draw_callbacks
 
std::optional< action_iddisplaying_overlays
 
class game::debug_hour_timer debug_hour_timer
 
pimpl< mapmap_ptr
 
pimpl< avataru_ptr
 
pimpl< live_viewliveview_ptr
 
live_viewliveview
 
pimpl< scent_mapscent_ptr
 
pimpl< timed_event_managertimed_event_manager_ptr
 
pimpl< event_busevent_bus_ptr
 
pimpl< stats_trackerstats_tracker_ptr
 
pimpl< kill_trackerkill_tracker_ptr
 
pimpl< achievements_trackerachievements_tracker_ptr
 
pimpl< memorial_loggermemorial_logger_ptr
 
pimpl< spell_eventsspell_events_ptr
 
pimpl< distribution_grid_trackergrid_tracker_ptr
 
pimpl< weather_managerweather_manager_ptr
 
shared_ptr_fast< playeru_shared_ptr
 
catacurses::window w_terrain_ptr
 
catacurses::window w_minimap_ptr
 
std::string sFilter
 
std::string list_item_upvote
 
std::string list_item_downvote
 
bool safe_mode_warning_logged = false
 
bool bVMonsterLookFire = false
 
character_id next_npc_id
 
std::list< shared_ptr_fast< npc > > active_npc
 
int next_mission_id = 0
 
std::set< character_idfollower_ids
 
int moves_since_last_save = 0
 
time_t last_save_timestamp
 
std::array< float, OVERMAP_LAYERSlatest_lightlevels
 
time_point remoteveh_cache_time
 
vehicleremoteveh_cache
 
bool npcs_dirty = false
 Has a NPC been spawned since last load? More...
 
bool critter_died = false
 Has anything died in this turn and needs to be cleaned up? More...
 
bool first_redraw_since_waiting_started = true
 Is this the first redraw since waiting (sleeping or activity) started. More...
 
bool zones_manager_open = false
 Is Zone manager open or not - changes graphics of some zone tiles. More...
 
std::unique_ptr< special_gamegamemode
 
int user_action_counter = 0
 
int tileset_zoom = 0
 How far the tileset should be zoomed out, 16 is default. More...
 
unsigned int seed = 0
 Seed for all the random numbers that should have consistent randomness (weather). More...
 
std::vector< tripointdestination_preview
 
std::chrono::time_point< std::chrono::steady_clock > last_mouse_edge_scroll
 
tripoint last_mouse_edge_scroll_vector_terrain
 
tripoint last_mouse_edge_scroll_vector_overmap
 
weak_ptr_fast< ui_adaptormain_ui_adaptor
 
std::unique_ptr< static_popupwait_popup
 

Friends

class editmap
 
class advanced_inventory
 
class main_menu
 
class monster_range
 
class Creature_range
 
distribution_grid_trackerget_distribution_grid_tracker ()
 Returns distribution grid tracker that is a part of the global game *g. More...
 
mapget_map ()
 
Characterget_player_character ()
 
avatarget_avatar ()
 
weather_managerget_weather ()
 

Detailed Description

Definition at line 143 of file game.h.

Member Enumeration Documentation

◆ vmenu_ret

enum class game::vmenu_ret : int
strongprivate
Enumerator
CHANGE_TAB 
QUIT 
FIRE 

Definition at line 767 of file game.h.

767 : int {
768 CHANGE_TAB,
769 QUIT,
770 FIRE, // Who knew, apparently you can do that in list_monsters
771 };

Constructor & Destructor Documentation

◆ game()

game::game ( )

Definition at line 302 of file game.cpp.

302 :
304 scent_ptr( *this ),
307 m( *map_ptr ),
308 u( *u_ptr ),
309 scent( *scent_ptr ),
311 uquit( QUIT_NO ),
312 new_game( false ),
314 mostseen( 0 ),
317 next_npc_id( 1 ),
318 next_mission_id( 1 ),
322 seed( 0 ),
323 last_mouse_edge_scroll( std::chrono::steady_clock::now() )
324{
332 world_generator = std::make_unique<worldfactory>();
333 // do nothing, everything that was in here is moved to init_data() which is called immediately after g = new game; in main.cpp
334 // The reason for this move is so that g is not uninitialized when it gets to installing the parts into vehicles.
335}
void subscribe(event_subscriber *)
Definition: event_bus.cpp:39
int mostseen
Definition: game.h:1022
pimpl< spell_events > spell_events_ptr
Definition: game.h:956
safe_mode_type safe_mode
Definition: game.h:1019
bool safe_mode_warning_logged
Definition: game.h:1033
pimpl< timed_event_manager > timed_event_manager_ptr
Definition: game.h:950
std::chrono::time_point< std::chrono::steady_clock > last_mouse_edge_scroll
Definition: game.h:1067
quit_status uquit
Used in main.cpp to determine what type of quit is being performed.
Definition: game.h:977
event_bus & events()
Definition: game.cpp:2713
pimpl< stats_tracker > stats_tracker_ptr
Definition: game.h:952
character_id next_npc_id
Definition: game.h:1035
pimpl< kill_tracker > kill_tracker_ptr
Definition: game.h:953
void reset_light_level()
Definition: game.cpp:3573
pimpl< memorial_logger > memorial_logger_ptr
Definition: game.h:955
shared_ptr_fast< player > u_shared_ptr
Definition: game.h:1024
pimpl< map > map_ptr
Definition: game.h:945
bool first_redraw_since_waiting_started
Is this the first redraw since waiting (sleeping or activity) started.
Definition: game.h:1050
pimpl< live_view > liveview_ptr
Definition: game.h:947
pimpl< achievements_tracker > achievements_tracker_ptr
Definition: game.h:954
pimpl< scent_map > scent_ptr
Definition: game.h:949
timed_event_manager & timed_events
Definition: game.h:964
unsigned int seed
Seed for all the random numbers that should have consistent randomness (weather).
Definition: game.h:1062
int next_mission_id
Definition: game.h:1037
bool new_game
True if the game has just started or loaded, else false.
Definition: game.h:979
pimpl< distribution_grid_tracker > grid_tracker_ptr
Definition: game.h:957
map & m
Definition: game.h:961
avatar & u
Definition: game.h:962
scent_map & scent
Definition: game.h:963
int user_action_counter
Definition: game.h:1056
live_view & liveview
Definition: game.h:948
int tileset_zoom
How far the tileset should be zoomed out, 16 is default.
Definition: game.h:1059
pimpl< avatar > u_ptr
Definition: game.h:946
time_point remoteveh_cache_time
Definition: game.h:1043
static void achievement_attained(const achievement *a)
Definition: game.cpp:295
static constexpr int DEFAULT_TILESET_ZOOM
Definition: game.h:41
@ SAFE_MODE_ON
Definition: game.h:78
@ QUIT_NO
Definition: game.h:68
mapbuffer MAPBUFFER
Definition: mapbuffer.cpp:40
const time_point before_time_starts
A time point that is always before the current turn, even when the game has just started.
Definition: calendar.cpp:25
For use with smart pointers when you don't actually want the deleter to do anything.
Definition: cata_utility.h:32
std::unique_ptr< worldfactory > world_generator

References achievements_tracker_ptr, events(), first_redraw_since_waiting_started, kill_tracker_ptr, memorial_logger_ptr, reset_light_level(), spell_events_ptr, stats_tracker_ptr, event_bus::subscribe(), and world_generator.

◆ ~game()

game::~game ( )
default

Member Function Documentation

◆ add_artifact_dreams()

void game::add_artifact_dreams ( )

Definition at line 11878 of file game.cpp.

11879{
11880 //If player is sleeping, get a dream from a carried artifact
11881 //Don't need to check that player is sleeping here, that's done before calling
11882 std::vector<item *> art_items = u.items_with( []( const item & it ) -> bool {
11883 return it.is_artifact();
11884 } );
11885 std::vector<item *> valid_arts;
11886 std::vector<std::vector<std::string>>
11887 valid_dreams; // Tracking separately so we only need to check its req once
11888 //Pull the list of dreams
11889 add_msg( m_debug, "Checking %s carried artifacts", art_items.size() );
11890 for( auto &it : art_items ) {
11891 //Pick only the ones with an applicable dream
11893 if( art && art->charge_req != ACR_NULL &&
11894 ( it->ammo_remaining() < it->ammo_capacity() ||
11895 it->ammo_capacity() == 0 ) ) { //or max 0 in case of wacky mod shenanigans
11896 add_msg( m_debug, "Checking artifact %s", it->tname() );
11897 if( check_art_charge_req( *it ) ) {
11898 add_msg( m_debug, " Has freq %s,%s", art->dream_freq_met, art->dream_freq_unmet );
11899 if( art->dream_freq_met > 0 && x_in_y( art->dream_freq_met, 100 ) ) {
11900 add_msg( m_debug, "Adding met dream from %s", it->tname() );
11901 valid_arts.push_back( it );
11902 valid_dreams.push_back( art->dream_msg_met );
11903 }
11904 } else {
11905 add_msg( m_debug, " Has freq %s,%s", art->dream_freq_met, art->dream_freq_unmet );
11906 if( art->dream_freq_unmet > 0 && x_in_y( art->dream_freq_unmet, 100 ) ) {
11907 add_msg( m_debug, "Adding unmet dream from %s", it->tname() );
11908 valid_arts.push_back( it );
11909 valid_dreams.push_back( art->dream_msg_unmet );
11910 }
11911 }
11912 }
11913 }
11914 if( !valid_dreams.empty() ) {
11915 add_msg( m_debug, "Found %s valid artifact dreams", valid_dreams.size() );
11916 const int selected = rng( 0, valid_arts.size() - 1 );
11917 auto it = valid_arts[selected];
11918 auto msg = random_entry( valid_dreams[selected] );
11919 const std::string &dream = string_format( _( msg ), it->tname() );
11920 add_msg( dream );
11921 } else {
11922 add_msg( m_debug, "Didn't have any dreams, sorry" );
11923 }
11924}
units::quantity< V, B > rng(const units::quantity< V, B > &min, const units::quantity< V, B > &max)
Definition: artifact.cpp:32
@ ACR_NULL
Definition: artifact.h:79
bool x_in_y(const time_duration &a, const time_duration &b)
Definition: calendar.cpp:521
This class is essentially a copyable unique pointer.
Definition: value_ptr.h:19
Definition: item.h:210
int ammo_remaining() const
Quantity of ammunition currently loaded in tool, gun or auxiliary gunmod.
Definition: item.cpp:7384
bool is_artifact() const
Definition: item.cpp:6978
int ammo_capacity() const
Maximum quantity of ammunition loadable for tool, gun or auxiliary gunmod.
Definition: item.cpp:7411
std::string tname(unsigned int quantity=1, bool with_prefix=true, unsigned int truncate=0) const
Return the (translated) item name.
Definition: item.cpp:4576
const itype * type
Definition: item.h:2170
std::vector< item * > items_with(const std::function< bool(const item &)> &filter)
Returns all items (including those within a container) matching the filter.
Definition: visitable.cpp:325
@ m_debug
Definition: enums.h:271
bool check_art_charge_req(item &it)
Definition: game.cpp:11581
void add_msg(std::string msg)
Definition: messages.cpp:910
V random_entry(const C &container, D default_value)
Returns a random entry in the container.
Definition: rng.h:88
std::string string_format(std::string_view format, Args &&...args)
Simple wrapper over string_formatter::parse.
cata::value_ptr< islot_artifact > artifact
Definition: itype.h:837
#define _(msg)
Definition: translations.h:116

References _, ACR_NULL, add_msg(), item::ammo_capacity(), item::ammo_remaining(), itype::artifact, check_art_charge_req(), item::is_artifact(), visitable< T >::items_with(), m_debug, random_entry(), rng(), string_format(), item::tname(), item::type, u, and x_in_y().

Referenced by do_turn().

◆ add_artifact_messages()

void game::add_artifact_messages ( const std::vector< art_effect_passive > &  effects)

Definition at line 11700 of file game.cpp.

11701{
11702 int net_str = 0;
11703 int net_dex = 0;
11704 int net_per = 0;
11705 int net_int = 0;
11706 int net_speed = 0;
11707
11708 for( auto &i : effects ) {
11709 switch( i ) {
11710 case AEP_STR_UP:
11711 net_str += 4;
11712 break;
11713 case AEP_DEX_UP:
11714 net_dex += 4;
11715 break;
11716 case AEP_PER_UP:
11717 net_per += 4;
11718 break;
11719 case AEP_INT_UP:
11720 net_int += 4;
11721 break;
11722 case AEP_ALL_UP:
11723 net_str += 2;
11724 net_dex += 2;
11725 net_per += 2;
11726 net_int += 2;
11727 break;
11728 case AEP_STR_DOWN:
11729 net_str -= 3;
11730 break;
11731 case AEP_DEX_DOWN:
11732 net_dex -= 3;
11733 break;
11734 case AEP_PER_DOWN:
11735 net_per -= 3;
11736 break;
11737 case AEP_INT_DOWN:
11738 net_int -= 3;
11739 break;
11740 case AEP_ALL_DOWN:
11741 net_str -= 2;
11742 net_dex -= 2;
11743 net_per -= 2;
11744 net_int -= 2;
11745 break;
11746
11747 case AEP_SPEED_UP:
11748 net_speed += 20;
11749 break;
11750 case AEP_SPEED_DOWN:
11751 net_speed -= 20;
11752 break;
11753
11754 case AEP_PBLUE:
11755 break; // No message
11756
11757 case AEP_SNAKES:
11758 add_msg( m_warning, _( "Your skin feels slithery." ) );
11759 break;
11760
11761 case AEP_INVISIBLE:
11762 add_msg( m_good, _( "You fade into invisibility!" ) );
11763 break;
11764
11765 case AEP_CLAIRVOYANCE:
11767 add_msg( m_good, _( "You can see through walls!" ) );
11768 break;
11769
11771 add_msg( m_good, _( "You can see through everything!" ) );
11772 break;
11773
11774 case AEP_STEALTH:
11775 add_msg( m_good, _( "Your steps stop making noise." ) );
11776 break;
11777
11778 case AEP_GLOW:
11779 add_msg( _( "A glow of light forms around you." ) );
11780 break;
11781
11782 case AEP_PSYSHIELD:
11783 add_msg( m_good, _( "Your mental state feels protected." ) );
11784 break;
11785
11787 add_msg( m_good, _( "You feel insulated." ) );
11788 break;
11789
11790 case AEP_CARRY_MORE:
11791 add_msg( m_good, _( "Your back feels strengthened." ) );
11792 break;
11793
11794 case AEP_FUN:
11795 add_msg( m_good, _( "You feel a pleasant tingle." ) );
11796 break;
11797
11798 case AEP_HUNGER:
11799 add_msg( m_warning, _( "You feel hungry." ) );
11800 break;
11801
11802 case AEP_THIRST:
11803 add_msg( m_warning, _( "You feel thirsty." ) );
11804 break;
11805
11806 case AEP_EVIL:
11807 add_msg( m_warning, _( "You feel an evil presence…" ) );
11808 break;
11809
11810 case AEP_SCHIZO:
11811 add_msg( m_bad, _( "You feel a tickle of insanity." ) );
11812 break;
11813
11814 case AEP_RADIOACTIVE:
11815 add_msg( m_warning, _( "Your skin prickles with radiation." ) );
11816 break;
11817
11818 case AEP_MUTAGENIC:
11819 add_msg( m_bad, _( "You feel your genetic makeup degrading." ) );
11820 break;
11821
11822 case AEP_ATTENTION:
11823 add_msg( m_warning, _( "You feel an otherworldly attention upon you…" ) );
11824 break;
11825
11826 case AEP_FORCE_TELEPORT:
11827 add_msg( m_bad, _( "You feel a force pulling you inwards." ) );
11828 break;
11829
11830 case AEP_MOVEMENT_NOISE:
11831 add_msg( m_warning, _( "You hear a rattling noise coming from inside yourself." ) );
11832 break;
11833
11834 case AEP_BAD_WEATHER:
11835 add_msg( m_warning, _( "You feel storms coming." ) );
11836 break;
11837
11838 case AEP_SICK:
11839 add_msg( m_bad, _( "You feel unwell." ) );
11840 break;
11841
11842 case AEP_SMOKE:
11843 add_msg( m_warning, _( "A cloud of smoke appears." ) );
11844 break;
11845 default:
11846 //Suppress warnings
11847 break;
11848 }
11849 }
11850
11851 std::string stat_info;
11852 if( net_str != 0 ) {
11853 stat_info += string_format( _( "Str %s%d! " ),
11854 ( net_str > 0 ? "+" : "" ), net_str );
11855 }
11856 if( net_dex != 0 ) {
11857 stat_info += string_format( _( "Dex %s%d! " ),
11858 ( net_dex > 0 ? "+" : "" ), net_dex );
11859 }
11860 if( net_int != 0 ) {
11861 stat_info += string_format( _( "Int %s%d! " ),
11862 ( net_int > 0 ? "+" : "" ), net_int );
11863 }
11864 if( net_per != 0 ) {
11865 stat_info += string_format( _( "Per %s%d! " ),
11866 ( net_per > 0 ? "+" : "" ), net_per );
11867 }
11868
11869 if( !stat_info.empty() ) {
11870 add_msg( m_neutral, stat_info );
11871 }
11872
11873 if( net_speed != 0 ) {
11874 add_msg( m_info, _( "Speed %s%d!" ), ( net_speed > 0 ? "+" : "" ), net_speed );
11875 }
11876}
@ m_good
Definition: enums.h:260
@ m_neutral
Definition: enums.h:267
@ m_info
Definition: enums.h:265
@ m_bad
Definition: enums.h:261
@ m_warning
Definition: enums.h:264
@ AEP_GLOW
Definition: enums.h:115
@ AEP_MUTAGENIC
Definition: enums.h:130
@ AEP_ALL_UP
Definition: enums.h:106
@ AEP_INT_UP
Definition: enums.h:105
@ AEP_INT_DOWN
Definition: enums.h:135
@ AEP_PER_UP
Definition: enums.h:104
@ AEP_PSYSHIELD
Definition: enums.h:116
@ AEP_CLAIRVOYANCE_PLUS
Definition: enums.h:142
@ AEP_MOVEMENT_NOISE
Definition: enums.h:139
@ AEP_STEALTH
Definition: enums.h:113
@ AEP_CARRY_MORE
Definition: enums.h:118
@ AEP_THIRST
Definition: enums.h:125
@ AEP_SPEED_UP
Definition: enums.h:107
@ AEP_EVIL
Definition: enums.h:127
@ AEP_ALL_DOWN
Definition: enums.h:136
@ AEP_DEX_UP
Definition: enums.h:103
@ AEP_SCHIZO
Definition: enums.h:128
@ AEP_DEX_DOWN
Definition: enums.h:133
@ AEP_FUN
Definition: enums.h:120
@ AEP_PER_DOWN
Definition: enums.h:134
@ AEP_FORCE_TELEPORT
Definition: enums.h:138
@ AEP_ATTENTION
Definition: enums.h:131
@ AEP_RADIOACTIVE
Definition: enums.h:129
@ AEP_SUPER_CLAIRVOYANCE
Definition: enums.h:112
@ AEP_BAD_WEATHER
Definition: enums.h:140
@ AEP_SICK
Definition: enums.h:141
@ AEP_CLAIRVOYANCE
Definition: enums.h:111
@ AEP_INVISIBLE
Definition: enums.h:110
@ AEP_STR_UP
Definition: enums.h:102
@ AEP_STR_DOWN
Definition: enums.h:132
@ AEP_HUNGER
Definition: enums.h:124
@ AEP_RESIST_ELECTRICITY
Definition: enums.h:117
@ AEP_PBLUE
Definition: enums.h:108
@ AEP_SPEED_DOWN
Definition: enums.h:137
@ AEP_SNAKES
Definition: enums.h:109
@ AEP_SMOKE
Definition: enums.h:126

References _, add_msg(), AEP_ALL_DOWN, AEP_ALL_UP, AEP_ATTENTION, AEP_BAD_WEATHER, AEP_CARRY_MORE, AEP_CLAIRVOYANCE, AEP_CLAIRVOYANCE_PLUS, AEP_DEX_DOWN, AEP_DEX_UP, AEP_EVIL, AEP_FORCE_TELEPORT, AEP_FUN, AEP_GLOW, AEP_HUNGER, AEP_INT_DOWN, AEP_INT_UP, AEP_INVISIBLE, AEP_MOVEMENT_NOISE, AEP_MUTAGENIC, AEP_PBLUE, AEP_PER_DOWN, AEP_PER_UP, AEP_PSYSHIELD, AEP_RADIOACTIVE, AEP_RESIST_ELECTRICITY, AEP_SCHIZO, AEP_SICK, AEP_SMOKE, AEP_SNAKES, AEP_SPEED_DOWN, AEP_SPEED_UP, AEP_STEALTH, AEP_STR_DOWN, AEP_STR_UP, AEP_SUPER_CLAIRVOYANCE, AEP_THIRST, m_bad, m_good, m_info, m_neutral, m_warning, and string_format().

◆ add_draw_callback()

void game::add_draw_callback ( shared_ptr_fast< draw_callback_t cb)

Definition at line 3024 of file game.cpp.

3025{
3026 draw_callbacks.erase(
3027 std::remove_if( draw_callbacks.begin(), draw_callbacks.end(),
3028 []( const weak_ptr_fast<draw_callback_t> &cbw ) {
3029 return cbw.expired();
3030 } ),
3031 draw_callbacks.end()
3032 );
3033 draw_callbacks.emplace_back( cb );
3034 cb->added = true;
3036}
void invalidate_main_ui_adaptor() const
Definition: game.cpp:2989
std::vector< weak_ptr_fast< draw_callback_t > > draw_callbacks
Definition: game.h:225
std::weak_ptr< T > weak_ptr_fast
Definition: memory_fast.h:17

References draw_callbacks, and invalidate_main_ui_adaptor().

Referenced by get_player_input(), list_items(), list_monsters(), look_around(), pickup(), and zones_manager().

◆ add_npc_follower()

void game::add_npc_follower ( const character_id id)

Add follower id to set of followers.

Definition at line 1874 of file game.cpp.

1875{
1876 follower_ids.insert( id );
1877 u.follower_ids.insert( id );
1878}
std::set< character_id > follower_ids
Definition: game.h:1038
std::set< character_id > follower_ids
Definition: player.h:261

References follower_ids, player::follower_ids, and u.

Referenced by validate_npc_followers().

◆ all_creatures()

game::Creature_range game::all_creatures ( )

Returns an anonymous range that contains all creatures.

The range allows iteration via a range-based for loop, e.g. for( Creature &critter : all_creatures() ) { ... }. One shall not store the returned range nor the iterators. One can freely remove and add creatures to the game during the iteration. Added creatures will not be iterated over.

Definition at line 12036 of file game.cpp.

12037{
12038 return Creature_range( *this );
12039}
friend class Creature_range
Definition: game.h:334

References Creature_range.

Referenced by draw_ter(), get_creature_if(), and get_creatures_if().

◆ all_monsters()

game::monster_range game::all_monsters ( )

Same as all_creatures but iterators only over monsters.

Definition at line 12041 of file game.cpp.

12042{
12043 return monster_range( *this );
12044}
friend class monster_range
Definition: game.h:333

References monster_range.

Referenced by cleanup_at_end(), disp_NPCs(), get_fishable_monsters(), monmove(), place_player_overmap(), shift_monsters(), start_game(), validate_mounted_npcs(), and vertical_move().

◆ all_npcs()

game::npc_range game::all_npcs ( )

Same as all_creatures but iterators only over npcs.

Definition at line 12046 of file game.cpp.

12047{
12048 return npc_range( *this );
12049}

Referenced by do_turn(), and get_npcs_if().

◆ allies()

std::vector< npc * > game::allies ( )

Get all living player allies.

Definition at line 11950 of file game.cpp.

11951{
11952 return get_npcs_if( [&]( const npc & guy ) {
11953 if( !guy.is_hallucination() ) {
11954 return guy.is_ally( g->u );
11955 } else {
11956 return false;
11957 }
11958 } );
11959}
std::vector< npc * > get_npcs_if(const std::function< bool(const npc &)> &pred)
Definition: game.cpp:11973
Definition: npc.h:744
bool is_hallucination() const override
Definition: npc.cpp:3284

References get_npcs_if(), and npc::is_hallucination().

◆ assign_mission_id()

int game::assign_mission_id ( )

Returns the next available mission id.

Definition at line 1862 of file game.cpp.

1863{
1864 int ret = next_mission_id;
1866 return ret;
1867}

References next_mission_id, and cata::hash64_detail::ret.

◆ assign_npc_id()

character_id game::assign_npc_id ( )

Definition at line 3581 of file game.cpp.

3582{
3584 ++next_npc_id;
3585 return ret;
3586}

References next_npc_id, and cata::hash64_detail::ret.

Referenced by load(), and start_game().

◆ autopilot_vehicles()

void game::autopilot_vehicles ( )

process vehicles that are following the player

Definition at line 1661 of file game.cpp.

1662{
1663 for( wrapped_vehicle &veh : m.get_vehicles() ) {
1664 vehicle *&v = veh.v;
1665 if( v->is_following ) {
1666 v->drive_to_local_target( m.getabs( u.pos() ), true );
1667 } else if( v->is_patrolling ) {
1668 v->autopilot_patrol();
1669 }
1670 }
1671}
const tripoint & pos() const override
Definition: character.cpp:601
tripoint getabs(const tripoint &p) const
Translates local (to this map) coordinates of a square to global absolute coordinates.
Definition: map.cpp:8407
VehicleList get_vehicles()
Definition: map.cpp:297
A vehicle as a whole with all its components.
Definition: vehicle.h:383
void autopilot_patrol()
Definition: vehicle.cpp:703
bool is_following
Definition: vehicle.h:1715
bool is_patrolling
Definition: vehicle.h:1716
void drive_to_local_target(const tripoint &target, bool follow_protocol)
Definition: vehicle.cpp:818

References vehicle::autopilot_patrol(), vehicle::drive_to_local_target(), map::get_vehicles(), map::getabs(), vehicle::is_following, vehicle::is_patrolling, m, Character::pos(), and u.

Referenced by do_turn().

◆ autosave()

void game::autosave ( )
private

Definition at line 11367 of file game.cpp.

11368{
11369 //Don't autosave if the min-autosave interval has not passed since the last autosave/quicksave.
11370 if( time( nullptr ) < last_save_timestamp + 60 * get_option<int>( "AUTOSAVE_MINUTES" ) ) {
11371 return;
11372 }
11373 quicksave(); //Driving checks are handled by quicksave()
11374}
time_t last_save_timestamp
Definition: game.h:1040
void quicksave()
Definition: game.cpp:11322
@ time
Recharges slowly with time.

References last_save_timestamp, quicksave(), and time.

Referenced by do_turn().

◆ butcher()

void game::butcher ( )
private

Definition at line 8333 of file game.cpp.

8334{
8335 static const std::string salvage_string = "salvage";
8336 if( u.controlling_vehicle ) {
8337 add_msg( m_info, _( "You can't butcher while driving!" ) );
8338 return;
8339 }
8340
8341 const int factor = u.max_quality( quality_id( "BUTCHER" ) );
8342 const int factorD = u.max_quality( quality_id( "CUT_FINE" ) );
8343 const std::string no_knife_msg = _( "You don't have a butchering tool." );
8344 const std::string no_corpse_msg = _( "There are no corpses here to butcher." );
8345
8346 //You can't butcher on sealed terrain- you have to smash/shovel/etc it open first
8347 if( m.has_flag( "SEALED", u.pos() ) ) {
8348 if( m.sees_some_items( u.pos(), u ) ) {
8349 add_msg( m_info, _( "You can't access the items here." ) );
8350 } else if( factor > INT_MIN || factorD > INT_MIN ) {
8351 add_msg( m_info, no_corpse_msg );
8352 } else {
8353 add_msg( m_info, no_knife_msg );
8354 }
8355 return;
8356 }
8357
8358 const item *first_item_without_tools = nullptr;
8359 // Indices of relevant items
8360 std::vector<map_stack::iterator> corpses;
8361 std::vector<map_stack::iterator> disassembles;
8362 std::vector<map_stack::iterator> salvageables;
8363 map_stack items = m.i_at( u.pos() );
8364 const inventory &crafting_inv = u.crafting_inventory();
8365
8366 // TODO: Properly handle different material whitelists
8367 // TODO: Improve quality of this section
8368 auto salvage_filter = []( item it ) {
8369 const auto usable = it.get_usable_item( salvage_string );
8370 return usable != nullptr;
8371 };
8372
8373 std::vector< item * > salvage_tools = u.items_with( salvage_filter );
8374 int salvage_tool_index = INT_MIN;
8375 item *salvage_tool = nullptr;
8376 const salvage_actor *salvage_iuse = nullptr;
8377 if( !salvage_tools.empty() ) {
8378 salvage_tool = salvage_tools.front();
8379 salvage_tool_index = u.get_item_position( salvage_tool );
8380 item *usable = salvage_tool->get_usable_item( salvage_string );
8381 salvage_iuse = dynamic_cast<const salvage_actor *>(
8382 usable->get_use( salvage_string )->get_actor_ptr() );
8383 }
8384
8385 // Reserve capacity for each to hold entire item set if necessary to prevent
8386 // reallocations later on
8387 corpses.reserve( items.size() );
8388 salvageables.reserve( items.size() );
8389 disassembles.reserve( items.size() );
8390
8391 // Split into corpses, disassemble-able, and salvageable items
8392 // It's not much additional work to just generate a corpse list and
8393 // clear it later, but does make the splitting process nicer.
8394 for( map_stack::iterator it = items.begin(); it != items.end(); ++it ) {
8395 if( it->is_corpse() ) {
8396 corpses.push_back( it );
8397 } else {
8398 if( ( salvage_tool_index != INT_MIN ) && salvage_iuse->valid_to_cut_up( *it ) ) {
8399 salvageables.push_back( it );
8400 }
8401 if( crafting::can_disassemble( u, *it, crafting_inv ).success() ) {
8402 disassembles.push_back( it );
8403 } else if( !first_item_without_tools ) {
8404 first_item_without_tools = &*it;
8405 }
8406 }
8407 }
8408
8409 // Clear corpses if butcher and dissect factors are INT_MIN
8410 if( factor == INT_MIN && factorD == INT_MIN ) {
8411 corpses.clear();
8412 }
8413
8414 if( corpses.empty() && disassembles.empty() && salvageables.empty() ) {
8415 if( factor > INT_MIN || factorD > INT_MIN ) {
8416 add_msg( m_info, no_corpse_msg );
8417 } else {
8418 add_msg( m_info, no_knife_msg );
8419 }
8420
8421 if( first_item_without_tools ) {
8422 add_msg( m_info, _( "You don't have the necessary tools to disassemble any items here." ) );
8423 // Just for the "You need x to disassemble y" messages
8424 const auto ret = crafting::can_disassemble( u, *first_item_without_tools, crafting_inv );
8425 if( !ret.success() ) {
8426 add_msg( m_info, "%s", ret.c_str() );
8427 }
8428 }
8429 return;
8430 }
8431
8432 Creature *hostile_critter = is_hostile_very_close();
8433 if( hostile_critter != nullptr ) {
8434 if( !query_yn( _( "You see %s nearby! Start butchering anyway?" ),
8435 hostile_critter->disp_name() ) ) {
8436 return;
8437 }
8438 }
8439
8440 // Magic indices for special butcher options
8441 enum : int {
8442 MULTISALVAGE = MAX_ITEM_IN_SQUARE + 1,
8443 MULTIBUTCHER,
8444 MULTIDISASSEMBLE_ONE,
8445 MULTIDISASSEMBLE_ALL,
8446 NUM_BUTCHER_ACTIONS
8447 };
8448 // What are we butchering (i.e.. which vector to pick indices from)
8449 enum {
8450 BUTCHER_CORPSE,
8451 BUTCHER_DISASSEMBLE,
8452 BUTCHER_SALVAGE,
8453 BUTCHER_OTHER // For multisalvage etc.
8454 } butcher_select = BUTCHER_CORPSE;
8455 // Index to std::vector of iterators...
8456 int indexer_index = 0;
8457
8458 // Generate the indexed stacks so we can display them nicely
8459 const auto disassembly_stacks = generate_butcher_stack_display( disassembles );
8460 const auto salvage_stacks = generate_butcher_stack_display( salvageables );
8461 // Always ask before cutting up/disassembly, but not before butchery
8462 size_t ret = 0;
8463 if( !corpses.empty() || !disassembles.empty() || !salvageables.empty() ) {
8464 uilist kmenu;
8465 kmenu.text = _( "Choose corpse to butcher / item to disassemble" );
8466
8467 size_t i = 0;
8468 // Add corpses, disassembleables, and salvagables to the UI
8469 add_corpses( kmenu, corpses, i );
8470 add_disassemblables( kmenu, disassembly_stacks, i );
8471 if( salvage_iuse && !salvageables.empty() ) {
8472 add_salvagables( kmenu, salvage_stacks, i, *salvage_iuse );
8473 }
8474
8475 if( corpses.size() > 1 ) {
8476 kmenu.addentry( MULTIBUTCHER, true, 'b', _( "Butcher everything" ) );
8477 }
8478 if( disassembles.size() > 1 ) {
8479 int time_to_disassemble = 0;
8480 int time_to_disassemble_all = 0;
8481 for( const auto &stack : disassembly_stacks ) {
8482 const int time = recipe_dictionary::get_uncraft( stack.first->typeId() ).time;
8483 time_to_disassemble += time;
8484 time_to_disassemble_all += time * stack.second;
8485 }
8486
8487 kmenu.addentry_col( MULTIDISASSEMBLE_ONE, true, 'D', _( "Disassemble everything once" ),
8488 to_string_clipped( time_duration::from_turns( time_to_disassemble / 100 ) ) );
8489 kmenu.addentry_col( MULTIDISASSEMBLE_ALL, true, 'd', _( "Disassemble everything recursively" ),
8490 to_string_clipped( time_duration::from_turns( time_to_disassemble_all / 100 ) ) );
8491 }
8492 if( salvage_iuse && salvageables.size() > 1 ) {
8493 int time_to_salvage = 0;
8494 for( const auto &stack : salvage_stacks ) {
8495 time_to_salvage += salvage_iuse->time_to_cut_up( *stack.first ) * stack.second;
8496 }
8497
8498 kmenu.addentry_col( MULTISALVAGE, true, 'z', _( "Cut up everything" ),
8499 to_string_clipped( time_duration::from_turns( time_to_salvage / 100 ) ) );
8500 }
8501
8502 kmenu.query();
8503
8504 if( kmenu.ret < 0 || kmenu.ret >= NUM_BUTCHER_ACTIONS ) {
8505 return;
8506 }
8507
8508 ret = static_cast<size_t>( kmenu.ret );
8509 if( ret >= MULTISALVAGE && ret < NUM_BUTCHER_ACTIONS ) {
8510 butcher_select = BUTCHER_OTHER;
8511 indexer_index = ret;
8512 } else if( ret < corpses.size() ) {
8513 butcher_select = BUTCHER_CORPSE;
8514 indexer_index = ret;
8515 } else if( ret < corpses.size() + disassembly_stacks.size() ) {
8516 butcher_select = BUTCHER_DISASSEMBLE;
8517 indexer_index = ret - corpses.size();
8518 } else if( ret < corpses.size() + disassembly_stacks.size() + salvage_stacks.size() ) {
8519 butcher_select = BUTCHER_SALVAGE;
8520 indexer_index = ret - corpses.size() - disassembly_stacks.size();
8521 } else {
8522 debugmsg( "Invalid butchery index: %d", ret );
8523 return;
8524 }
8525 }
8526
8527 if( !u.has_morale_to_craft() ) {
8528 if( butcher_select == BUTCHER_CORPSE || indexer_index == MULTIBUTCHER ) {
8529 add_msg( m_info,
8530 _( "You are not in the mood and the prospect of guts and blood on your hands convinces you to turn away." ) );
8531 } else {
8532 add_msg( m_info,
8533 _( "You are not in the mood and the prospect of work stops you before you begin." ) );
8534 }
8535 return;
8536 }
8537 const auto helpers = character_funcs::get_crafting_helpers( u );
8538 for( const npc *np : helpers ) {
8539 add_msg( m_info, _( "%s helps with this task…" ), np->name );
8540 }
8541 switch( butcher_select ) {
8542 case BUTCHER_OTHER:
8543 switch( indexer_index ) {
8544 case MULTISALVAGE:
8545 u.assign_activity( activity_id( "ACT_LONGSALVAGE" ), 0, salvage_tool_index );
8546 break;
8547 case MULTIBUTCHER:
8548 butcher_submenu( corpses );
8549 for( map_stack::iterator &it : corpses ) {
8550 u.activity.targets.emplace_back( map_cursor( u.pos() ), &*it );
8551 }
8552 break;
8553 case MULTIDISASSEMBLE_ONE:
8554 crafting::disassemble_all( u, false );
8555 break;
8556 case MULTIDISASSEMBLE_ALL:
8558 break;
8559 default:
8560 debugmsg( "Invalid butchery type: %d", indexer_index );
8561 return;
8562 }
8563 break;
8564 case BUTCHER_CORPSE: {
8565 butcher_submenu( corpses, indexer_index );
8566 u.activity.targets.emplace_back( map_cursor( u.pos() ), &*corpses[indexer_index] );
8567 }
8568 break;
8569 case BUTCHER_DISASSEMBLE: {
8570 // Pick index of first item in the disassembly stack
8571 item *const target = &*disassembly_stacks[indexer_index].first;
8573 }
8574 break;
8575 case BUTCHER_SALVAGE: {
8576 if( !salvage_iuse || !salvage_tool ) {
8577 debugmsg( "null salve_iuse or salvage_tool" );
8578 } else {
8579 // Pick index of first item in the salvage stack
8580 item *const target = &*salvage_stacks[indexer_index].first;
8581 item_location item_loc( map_cursor( u.pos() ), target );
8582 salvage_iuse->cut_up( u, *salvage_tool, item_loc );
8583 }
8584 }
8585 break;
8586 }
8587}
string_id< activity_type > activity_id
Definition: activity_type.h:15
static std::string to_string_clipped(const int num, const clipped_unit type, const clipped_align align)
Definition: calendar.cpp:228
bool controlling_vehicle
Definition: character.h:254
player_activity activity
Definition: character.h:1576
int get_item_position(const item *it) const
Returns the item position (suitable for i_at or similar) of a specific item.
Definition: character.cpp:2355
bool has_morale_to_craft() const
Definition: crafting.cpp:337
const inventory & crafting_inventory(bool clear_path)
Definition: crafting.cpp:557
void assign_activity(const activity_id &type, int moves=calendar::INDEFINITELY_LONG, int index=-1, int pos=INT_MIN, const std::string &name="")
Legacy activity assignment, does not work for any activites using the new activity_actor class and ma...
Definition: character.cpp:9196
virtual std::string disp_name(bool possessive=false, bool capitalize_first=false) const =0
Creature * is_hostile_very_close()
Definition: game.cpp:3595
A lightweight handle to an item independent of it's location Unlike a raw pointer can be (de-)seriali...
Definition: item_location.h:23
size_t size() const
Definition: item_stack.cpp:10
iterator begin()
Definition: item_stack.cpp:28
iterator end()
Definition: item_stack.cpp:33
item * get_usable_item(const std::string &use_name)
Checks this item and its contents (recursively) for types that have use_function with type use_name.
Definition: item.cpp:7975
const use_function * get_use(const std::string &use_name) const
Returns the pointer to use_function with name use_name assigned to the type of this item or any of it...
Definition: item.cpp:7949
Definition: map.h:105
bool has_flag(const std::string &flag, const tripoint &p) const
Definition: map.cpp:2375
map_stack i_at(const tripoint &p)
Definition: map.cpp:4210
bool sees_some_items(const tripoint &p, const Creature &who) const
Check if creature can see some items at p.
Definition: map.cpp:4856
std::vector< item_location > targets
static const recipe & get_uncraft(const itype_id &id)
Returns disassembly recipe (or null recipe if no match)
int time
Definition: recipe.h:61
Cuts stuff up into components.
Definition: iuse_actor.h:567
bool valid_to_cut_up(const item &it) const
int cut_up(player &p, item &it, item_location &cut) const
int time_to_cut_up(const item &it) const
static constexpr time_duration from_turns(const T t)
Named constructors to get a duration representing a multiple of the named time units.
Definition: calendar.h:204
uilist: scrolling vertical list menu
Definition: ui.h:187
int ret
Definition: ui.h:412
void addentry_col(int r, bool e, int k, const std::string &str, const std::string &column, const std::string &desc="")
Definition: ui.cpp:962
std::string text
Definition: ui.h:320
void addentry(const std::string &str)
Definition: ui.cpp:942
int max_quality(const quality_id &qual) const
Return maximum tool quality level provided by instance or INT_MIN if not found.
Definition: visitable.cpp:277
#define debugmsg(...)
Debug message of level DL::Error and class DC::DebugMsg, also includes the source file name and line,...
Definition: debug.h:75
static void butcher_submenu(const std::vector< map_stack::iterator > &corpses, int corpse=-1)
Definition: game.cpp:8183
static void add_salvagables(uilist &menu, const std::vector< std::pair< map_stack::iterator, int > > &stacks, size_t &menu_index, const salvage_actor &salvage_iuse)
Definition: game.cpp:8141
static void add_disassemblables(uilist &menu, const std::vector< std::pair< map_stack::iterator, int > > &stacks, size_t &menu_index)
Definition: game.cpp:8162
static std::vector< std::pair< map_stack::iterator, int > > generate_butcher_stack_display(const std::vector< map_stack::iterator > &its)
Definition: game.cpp:8094
static void add_corpses(uilist &menu, const std::vector< map_stack::iterator > &its, size_t &menu_index)
Definition: game.cpp:8129
static constexpr int MAX_ITEM_IN_SQUARE
void query(bool loop=true, int timeout=-1)
Handle input and update display.
Definition: ui.cpp:838
std::vector< npc * > get_crafting_helpers(const Character &who, int max)
Returns nearby NPCs ready and willing to help with crafting or some other manual task.
ret_val< bool > can_disassemble(const Character &who, const item &obj, const inventory &inv)
Check if character can disassemble an item using the given crafting inventory.
Definition: crafting.cpp:1888
bool disassemble(avatar &you)
Prompt for an item to disassemble, then start activity.
Definition: crafting.cpp:2072
bool disassemble_all(avatar &you, bool recursively)
Start an activity to disassemble all items in avatar's square.
Definition: crafting.cpp:2083
bool query_yn(const std::string &text)
Definition: output.cpp:698
iuse_actor * get_actor_ptr()
Definition: iuse.h:316
string_id< quality > quality_id
Definition: type_id.h:184

References _, Character::activity, add_corpses(), add_disassemblables(), add_msg(), add_salvagables(), uilist::addentry(), uilist::addentry_col(), Character::assign_activity(), item_stack::begin(), butcher_submenu(), crafting::can_disassemble(), Character::controlling_vehicle, Character::crafting_inventory(), salvage_actor::cut_up(), debugmsg, crafting::disassemble(), crafting::disassemble_all(), Creature::disp_name(), item_stack::end(), time_duration::from_turns(), generate_butcher_stack_display(), use_function::get_actor_ptr(), character_funcs::get_crafting_helpers(), Character::get_item_position(), recipe_dictionary::get_uncraft(), item::get_usable_item(), item::get_use(), map::has_flag(), Character::has_morale_to_craft(), map::i_at(), is_hostile_very_close(), visitable< T >::items_with(), m, m_info, MAX_ITEM_IN_SQUARE, visitable< T >::max_quality(), Character::pos(), uilist::query(), query_yn(), cata::hash64_detail::ret, uilist::ret, map::sees_some_items(), item_stack::size(), player_activity::targets, uilist::text, recipe::time, time, salvage_actor::time_to_cut_up(), to_string_clipped(), u, and salvage_actor::valid_to_cut_up().

Referenced by handle_action().

◆ calc_driving_offset()

void game::calc_driving_offset ( vehicle veh = nullptr)

Definition at line 1247 of file game.cpp.

1248{
1249 if( veh == nullptr || !get_option<bool>( "DRIVING_VIEW_OFFSET" ) ) {
1251 return;
1252 }
1253 const int g_light_level = static_cast<int>( light_level( u.posz() ) );
1254 const int light_sight_range = u.sight_range( g_light_level );
1255 int sight = std::max( veh_lumi( *veh ), light_sight_range );
1256
1257 // The maximal offset will leave at least this many tiles
1258 // between the PC and the edge of the main window.
1259 static const int border_range = 2;
1260 point max_offset( ( getmaxx( w_terrain ) + 1 ) / 2 - border_range - 1,
1261 ( getmaxy( w_terrain ) + 1 ) / 2 - border_range - 1 );
1262
1263 // velocity at or below this results in no offset at all
1264 static const float min_offset_vel = 1 * vehicles::vmiph_per_tile;
1265 // velocity at or above this results in maximal offset
1266 static const float max_offset_vel = std::min( max_offset.y, max_offset.x ) *
1268 float velocity = veh->velocity;
1269 rl_vec2d offset = veh->move_vec();
1270 if( !veh->skidding && veh->player_in_control( u ) &&
1271 std::abs( veh->cruise_velocity - veh->velocity ) < 7 * vehicles::vmiph_per_tile ) {
1272 // Use the cruise controlled velocity, but only if
1273 // it is not too different from the actual velocity.
1274 // The actual velocity changes too often (see above slowdown).
1275 // Using it makes would make the offset change far too often.
1276 offset = veh->face_vec();
1277 velocity = veh->cruise_velocity;
1278 }
1279 float rel_offset;
1280 if( std::fabs( velocity ) < min_offset_vel ) {
1281 rel_offset = 0;
1282 } else if( std::fabs( velocity ) > max_offset_vel ) {
1283 rel_offset = ( velocity > 0 ) ? 1 : -1;
1284 } else {
1285 rel_offset = ( velocity - min_offset_vel ) / ( max_offset_vel - min_offset_vel );
1286 }
1287 // Squeeze into the corners, by making the offset vector longer,
1288 // the PC is still in view as long as both offset.x and
1289 // offset.y are <= 1
1290 if( std::fabs( offset.x ) > std::fabs( offset.y ) && std::fabs( offset.x ) > 0.2 ) {
1291 offset.y /= std::fabs( offset.x );
1292 offset.x = ( offset.x > 0 ) ? +1 : -1;
1293 } else if( std::fabs( offset.y ) > 0.2 ) {
1294 offset.x /= std::fabs( offset.y );
1295 offset.y = offset.y > 0 ? +1 : -1;
1296 }
1297 offset.x *= rel_offset;
1298 offset.y *= rel_offset;
1299 offset.x *= max_offset.x;
1300 offset.y *= max_offset.y;
1301 // [ ----@---- ] sight=6
1302 // [ --@------ ] offset=2
1303 // [ -@------# ] offset=3
1304 // can see sights square in every direction, total visible area is
1305 // (2*sight+1)x(2*sight+1), but the window is only
1306 // getmaxx(w_terrain) x getmaxy(w_terrain)
1307 // The area outside of the window is maxoff (sight-getmax/2).
1308 // If that value is <= 0, the whole visible area fits the window.
1309 // don't apply the view offset at all.
1310 // If the offset is > maxoff, only apply at most maxoff, everything
1311 // above leads to invisible area in front of the car.
1312 // It will display (getmax/2+offset) squares in one direction and
1313 // (getmax/2-offset) in the opposite direction (centered on the PC).
1314 const point maxoff( ( sight * 2 + 1 - getmaxx( w_terrain ) ) / 2,
1315 ( sight * 2 + 1 - getmaxy( w_terrain ) ) / 2 );
1316 if( maxoff.x <= 0 ) {
1317 offset.x = 0;
1318 } else if( offset.x > 0 && offset.x > maxoff.x ) {
1319 offset.x = maxoff.x;
1320 } else if( offset.x < 0 && -offset.x > maxoff.x ) {
1321 offset.x = -maxoff.x;
1322 }
1323 if( maxoff.y <= 0 ) {
1324 offset.y = 0;
1325 } else if( offset.y > 0 && offset.y > maxoff.y ) {
1326 offset.y = maxoff.y;
1327 } else if( offset.y < 0 && -offset.y > maxoff.y ) {
1328 offset.y = -maxoff.y;
1329 }
1330
1331 // Turn the offset into a vector that increments the offset toward the desired position
1332 // instead of setting it there instantly, should smooth out jerkiness.
1333 const point offset_difference( -driving_view_offset + point( offset.x, offset.y ) );
1334
1335 const point offset_sign( ( offset_difference.x < 0 ) ? -1 : 1,
1336 ( offset_difference.y < 0 ) ? -1 : 1 );
1337 // Shift the current offset in the direction of the calculated offset by one tile
1338 // per draw event, but snap to calculated offset if we're close enough to avoid jitter.
1339 offset.x = ( std::abs( offset_difference.x ) > 1 ) ?
1340 ( driving_view_offset.x + offset_sign.x ) : offset.x;
1341 offset.y = ( std::abs( offset_difference.y ) > 1 ) ?
1342 ( driving_view_offset.y + offset_sign.y ) : offset.y;
1343
1344 set_driving_view_offset( point( offset.x, offset.y ) );
1345}
int posz() const override
Definition: character.h:801
int sight_range(int light_level) const override
Returns the player's sight range.
Definition: character.cpp:606
point driving_view_offset
Definition: game.h:996
catacurses::window w_terrain
Definition: game.h:986
void set_driving_view_offset(point p)
Definition: game.cpp:1598
unsigned char light_level(int zlev) const
Returns coarse number-of-squares of visibility at the current light level.
Definition: game.cpp:3567
rl_vec2d move_vec() const
rl_vec2d face_vec() const
bool skidding
Definition: vehicle.h:1731
bool player_in_control(const Character &p) const
Definition: vehicle.cpp:279
int velocity
Definition: vehicle.h:1650
int cruise_velocity
Definition: vehicle.h:1652
static int veh_lumi(vehicle &veh)
Definition: game.cpp:1229
int getmaxx(const window &win)
Definition: ncurses_def.cpp:59
int getmaxy(const window &win)
Definition: ncurses_def.cpp:64
quantity< V, U > fabs(quantity< V, U > q)
Definition: units_def.h:136
constexpr float vmiph_per_tile
Definition: vehicle.h:67
static constexpr point point_zero
Definition: point.h:260
Definition: point.h:35
int y
Definition: point.h:39
int x
Definition: point.h:38
float y
Definition: point_float.h:13
float x
Definition: point_float.h:12

References vehicle::cruise_velocity, driving_view_offset, units::fabs(), vehicle::face_vec(), catacurses::getmaxx(), catacurses::getmaxy(), light_level(), vehicle::move_vec(), vehicle::player_in_control(), point_zero, Character::posz(), set_driving_view_offset(), Character::sight_range(), vehicle::skidding, u, veh_lumi(), vehicle::velocity, vehicles::vmiph_per_tile, w_terrain, point::x, rl_vec2d::x, point::y, and rl_vec2d::y.

Referenced by do_turn().

◆ cancel_activity_or_ignore_query()

bool game::cancel_activity_or_ignore_query ( distraction_type  type,
const std::string &  text 
)

Asks if the player wants to cancel their activity and if so cancels it.

Additionally checks if the player wants to ignore further distractions.

Definition at line 1700 of file game.cpp.

1701{
1704 return false;
1705 }
1706 if( u.has_distant_destination() ) {
1707 if( cancel_auto_move( u, text ) ) {
1708 return true;
1709 } else {
1711 return false;
1712 }
1713 }
1714 const bool force_uc = get_option<bool>( "FORCE_CAPITAL_YN" );
1715 const auto &allow_key = force_uc ? input_context::disallow_lower_case
1717
1718 const auto &action = query_popup()
1719 .context( "CANCEL_ACTIVITY_OR_IGNORE_QUERY" )
1720 .message( force_uc ?
1721 pgettext( "cancel_activity_or_ignore_query",
1722 "<color_light_red>%s %s (Case Sensitive)</color>" ) :
1723 pgettext( "cancel_activity_or_ignore_query",
1724 "<color_light_red>%s %s</color>" ),
1725 text, u.activity.get_stop_phrase() )
1726 .option( "YES", allow_key )
1727 .option( "NO", allow_key )
1728 .option( "MANAGER", allow_key )
1729 .option( "IGNORE", allow_key )
1730 .query()
1731 .action;
1732
1733 if( action == "YES" ) {
1735 return true;
1736 }
1737 if( action == "IGNORE" ) {
1739 for( auto &activity : u.backlog ) {
1740 activity.ignore_distraction( type );
1741 }
1742 }
1743 if( action == "MANAGER" ) {
1746 return true;
1747 }
1748
1751
1752 return false;
1753}
void set_destination(const std::vector< tripoint > &route, const player_activity &new_destination_activity=player_activity())
void cancel_activity()
Definition: character.cpp:9239
std::vector< tripoint > & get_auto_move_route()
std::list< player_activity > backlog
Definition: character.h:1577
bool has_distant_destination() const
static const input_event_filter allow_all_keys
Definition: input.h:541
static const input_event_filter disallow_lower_case
Definition: input.h:540
bool is_distraction_ignored(distraction_type type) const
std::string get_stop_phrase() const
void ignore_distraction(distraction_type type)
UI class for displaying messages or querying player input with popups.
Definition: popup.h:39
query_popup & context(const std::string &cat)
Specify the input context.
Definition: popup.cpp:21
query_popup & option(const std::string &opt)
Specify an action as an option.
Definition: popup.cpp:28
result query()
Query until a valid action or an error happens and return the result.
Definition: popup.cpp:348
query_popup & message(const std::string &fmt, Args &&... args)
Specify the query message.
Definition: popup.h:91
@ action
Definition: dialogue.h:36
distraction_manager::distraction_manager_gui & get_distraction_manager()
static bool cancel_auto_move(player &p, const std::string &text)
Definition: game.cpp:1687
void redraw()
Invalidate the top window and redraw all invalidated windows.
Definition: ui_manager.cpp:389
void refresh_display()
Make changes made to the display visible to the user immediately.
std::string action
Definition: popup.h:68
const char * pgettext(const char *context, const char *msgid)

References action, query_popup::result::action, Character::activity, input_context::allow_all_keys, Character::backlog, Character::cancel_activity(), cancel_auto_move(), query_popup::context(), input_context::disallow_lower_case, Character::get_auto_move_route(), get_distraction_manager(), player_activity::get_stop_phrase(), Character::has_distant_destination(), player_activity::ignore_distraction(), invalidate_main_ui_adaptor(), player_activity::is_distraction_ignored(), query_popup::message(), query_popup::option(), pgettext(), query_popup::query(), ui_manager::redraw(), refresh_display(), Character::set_destination(), distraction_manager::distraction_manager_gui::show(), type, and u.

Referenced by mon_info_update(), monmove(), and process_voluntary_act_interrupt().

◆ cancel_activity_query()

bool game::cancel_activity_query ( const std::string &  text)

Asks if the player wants to cancel their activity, and if so cancels it.

Definition at line 1755 of file game.cpp.

1756{
1758 if( u.has_distant_destination() ) {
1759 if( cancel_auto_move( u, text ) ) {
1760 return true;
1761 } else {
1763 return false;
1764 }
1765 }
1766 if( !u.activity ) {
1767 return false;
1768 }
1769 if( query_yn( "%s %s", text, u.activity.get_stop_phrase() ) ) {
1773 return true;
1774 }
1775 return false;
1776}
void clear_destination()
void resume_backlog_activity()
Definition: character.cpp:9271

References Character::activity, Character::cancel_activity(), cancel_auto_move(), Character::clear_destination(), Character::get_auto_move_route(), player_activity::get_stop_phrase(), Character::has_distant_destination(), invalidate_main_ui_adaptor(), query_yn(), Character::resume_backlog_activity(), Character::set_destination(), and u.

Referenced by handle_key_blocking_activity().

◆ catch_a_monster()

void game::catch_a_monster ( monster fish,
const tripoint pos,
player p,
const time_duration catch_duration 
)

Picks and spawns a random fish from the remaining fish list when a fish is caught.

Definition at line 1673 of file game.cpp.

1675{
1676 //spawn the corpse, rotten by a part of the duration
1678 catch_duration ) ) );
1679 if( u.sees( pos ) ) {
1680 u.add_msg_if_player( m_good, _( "You caught a %s." ), fish->type->nname() );
1681 }
1682 //quietly kill the caught
1683 fish->no_corpse_quiet = true;
1684 fish->die( p );
1685}
bool sees(const tripoint &t, bool is_player=false, int range_mod=0) const override
static item make_corpse(const mtype_id &mt=string_id< mtype >::NULL_ID(), time_point turn=calendar::turn, const std::string &name="", int upgrade_time=-1)
Make a corpse of the given monster type.
Definition: item.cpp:512
item & add_item_or_charges(const tripoint &pos, item obj, bool overflow=true)
Adds an item to map tile or stacks charges.
Definition: map.cpp:4355
bool no_corpse_quiet
Definition: monster.h:482
void die(Creature *killer) override
Empty function.
Definition: monster.cpp:2297
const mtype * type
Definition: monster.h:478
void add_msg_if_player(const std::string &msg) const override
Definition: player.cpp:367
time_point turn
Definition: calendar.cpp:36
mtype_id id
Definition: mtype.h:241
std::string nname(unsigned int quantity=1) const
Definition: mtype.cpp:65

References _, map::add_item_or_charges(), player::add_msg_if_player(), monster::die(), mtype::id, m, m_good, item::make_corpse(), mtype::nname(), monster::no_corpse_quiet, rng(), Character::sees(), calendar::turn, monster::type, and u.

◆ chat()

void game::chat ( )
private

Definition at line 397 of file npctalk.cpp.

398{
399 int volume = u.get_shout_volume();
400
401 const std::vector<npc *> available = get_npcs_if( [&]( const npc & guy ) {
402 // TODO: Get rid of the z-level check when z-level vision gets "better"
403 return u.posz() == guy.posz() && u.sees( guy.pos() ) &&
404 rl_dist( u.pos(), guy.pos() ) <= SEEX * 2;
405 } );
406 const int available_count = available.size();
407 const std::vector<npc *> followers = get_npcs_if( [&]( const npc & guy ) {
408 return guy.is_player_ally() && guy.is_following() && guy.can_hear( u.pos(), volume );
409 } );
410 const int follower_count = followers.size();
411 const std::vector<npc *> guards = get_npcs_if( [&]( const npc & guy ) {
412 return guy.mission == NPC_MISSION_GUARD_ALLY &&
413 guy.companion_mission_role_id != "FACTION_CAMP" &&
414 guy.can_hear( u.pos(), volume );
415 } );
416 const int guard_count = guards.size();
417
418 if( u.has_trait( trait_PROF_FOODP ) && !( u.is_wearing( itype_id( "foodperson_mask" ) ) ||
419 u.is_wearing( itype_id( "foodperson_mask_on" ) ) ) ) {
420 u.add_msg_if_player( m_warning, _( "You can't speak without your face!" ) );
421 return;
422 }
423 std::vector<vehicle *> animal_vehicles;
424 std::vector<vehicle *> following_vehicles;
425 std::vector<vehicle *> magic_vehicles;
426 std::vector<vehicle *> magic_following_vehicles;
427 for( auto &veh : m.get_vehicles() ) {
428 auto &v = veh.v;
429 if( v->has_engine_type( fuel_type_animal, false ) && v->is_owned_by( u ) ) {
430 animal_vehicles.push_back( v );
431 if( v->is_following ) {
432 following_vehicles.push_back( v );
433 }
434 }
435 if( v->magic ) {
436 for( const vpart_reference &vp : v->get_all_parts() ) {
437 const vpart_info &vpi = vp.info();
438 if( vpi.has_flag( "MAGIC_FOLLOW" ) ) {
439 magic_vehicles.push_back( v );
440 if( v->is_following ) {
441 magic_following_vehicles.push_back( v );
442 }
443 break;
444 }
445 }
446 }
447 }
448
449 uilist nmenu;
450 nmenu.text = std::string( _( "What do you want to do?" ) );
451
452 if( !available.empty() ) {
453 nmenu.addentry( NPC_CHAT_TALK, true, 't', available_count == 1 ?
454 string_format( _( "Talk to %s" ), available.front()->name ) :
455 _( "Talk to…" )
456 );
457 }
458 nmenu.addentry( NPC_CHAT_YELL, true, 'a', _( "Yell" ) );
459 nmenu.addentry( NPC_CHAT_SENTENCE, true, 'b', _( "Yell a sentence" ) );
460 if( !animal_vehicles.empty() ) {
462 _( "Whistle at your animals pulling vehicles to follow you." ) );
463 }
464 if( !magic_vehicles.empty() ) {
466 _( "Utter a magical command that will order your magical vehicles to follow you." ) );
467 }
468 if( !magic_following_vehicles.empty() ) {
470 _( "Utter a magical command that will order your magical vehicles to stop following you." ) );
471 }
472 if( !following_vehicles.empty() ) {
474 _( "Whistle at your animals pulling vehicles to stop following you." ) );
475 }
476 if( !guards.empty() ) {
477 nmenu.addentry( NPC_CHAT_FOLLOW, true, 'f', guard_count == 1 ?
478 string_format( _( "Tell %s to follow" ), guards.front()->name ) :
479 _( "Tell someone to follow…" )
480 );
481 }
482 if( !followers.empty() ) {
483 nmenu.addentry( NPC_CHAT_GUARD, true, 'g', follower_count == 1 ?
484 string_format( _( "Tell %s to guard" ), followers.front()->name ) :
485 _( "Tell someone to guard…" )
486 );
487 nmenu.addentry( NPC_CHAT_MOVE_TO_POS, true, 'G',
488 follower_count == 1 ? string_format( _( "Tell %s to move to location" ),
489 followers.front()->get_name() ) : _( "Tell someone to move to location…" ) );
490 nmenu.addentry( NPC_CHAT_AWAKE, true, 'w', _( "Tell everyone on your team to wake up" ) );
491 nmenu.addentry( NPC_CHAT_MOUNT, true, 'M', _( "Tell everyone on your team to mount up" ) );
492 nmenu.addentry( NPC_CHAT_DISMOUNT, true, 'm', _( "Tell everyone on your team to dismount" ) );
493 nmenu.addentry( NPC_CHAT_DANGER, true, 'D',
494 _( "Tell everyone on your team to prepare for danger" ) );
495 nmenu.addentry( NPC_CHAT_CLEAR_OVERRIDES, true, 'r',
496 _( "Tell everyone on your team to relax (Clear Overrides)" ) );
497 nmenu.addentry( NPC_CHAT_ORDERS, true, 'o', _( "Tell everyone on your team to temporarily…" ) );
498 }
499 std::string message;
500 std::string yell_msg;
501 bool is_order = true;
502 nmenu.query();
503
504 if( nmenu.ret < 0 ) {
505 return;
506 }
507
508 switch( nmenu.ret ) {
509 case NPC_CHAT_TALK: {
510 const int npcselect = npc_select_menu( available, _( "Talk to whom?" ), false );
511 if( npcselect < 0 ) {
512 return;
513 }
514 available[npcselect]->talk_to_u();
515 break;
516 }
517 case NPC_CHAT_YELL:
518 is_order = false;
519 message = _( "loudly." );
520 break;
521 case NPC_CHAT_SENTENCE: {
522 std::string popupdesc = _( "Enter a sentence to yell" );
524 popup.title( _( "Yell a sentence" ) )
525 .width( 64 )
526 .description( popupdesc )
527 .identifier( "sentence" )
528 .max_length( 128 )
529 .query();
530 yell_msg = popup.text();
531 is_order = false;
532 break;
533 }
534 case NPC_CHAT_GUARD: {
535 const int npcselect = npc_select_menu( followers, _( "Who should guard here?" ) );
536 if( npcselect < 0 ) {
537 return;
538 }
539 if( npcselect == follower_count ) {
540 for( npc *them : followers ) {
542 }
543 yell_msg = _( "Everyone guard here!" );
544 } else {
545 talk_function::assign_guard( *followers[npcselect] );
546 yell_msg = string_format( _( "Guard here, %s!" ), followers[npcselect]->name );
547 }
548 break;
549 }
551 const int npcselect = npc_select_menu( followers, _( "Who should move?" ) );
552 if( npcselect < 0 ) {
553 return;
554 }
555
556 map &here = get_map();
557 std::optional<tripoint> p = look_around();
558
559 if( !p ) {
560 return;
561 }
562
563 if( here.impassable( tripoint( *p ) ) ) {
564 add_msg( m_info, _( "This destination can't be reached." ) );
565 return;
566 }
567
568 const auto &to = p.value();
569 if( npcselect == follower_count ) {
570 for( npc *them : followers ) {
571 tripoint_abs_ms( here.getabs( to ) );
572 them->goto_to_this_pos = here.getglobal( to );
573 }
574 yell_msg = _( "Everyone move there!" );
575 } else {
576 followers[npcselect]->goto_to_this_pos = here.getglobal( to );
577 yell_msg = string_format( _( "Move there, %s!" ), followers[npcselect]->get_name() );
578 }
579 break;
580 }
581 case NPC_CHAT_FOLLOW: {
582 const int npcselect = npc_select_menu( guards, _( "Who should follow you?" ) );
583 if( npcselect < 0 ) {
584 return;
585 }
586 if( npcselect == guard_count ) {
587 for( npc *them : guards ) {
589 }
590 yell_msg = _( "Everyone follow me!" );
591 } else {
592 talk_function::stop_guard( *guards[npcselect] );
593 yell_msg = string_format( _( "Follow me, %s!" ), guards[npcselect]->name );
594 }
595 break;
596 }
597 case NPC_CHAT_AWAKE:
598 for( npc *them : followers ) {
599 talk_function::wake_up( *them );
600 }
601 yell_msg = _( "Stay awake!" );
602 break;
603 case NPC_CHAT_MOUNT:
604 for( npc *them : followers ) {
605 if( them->has_effect( effect_riding ) ) {
606 continue;
607 }
609 }
610 yell_msg = _( "Mount up!" );
611 break;
613 for( npc *them : followers ) {
614 if( them->has_effect( effect_riding ) ) {
615 them->npc_dismount();
616 }
617 }
618 yell_msg = _( "Dismount!" );
619 break;
620 case NPC_CHAT_DANGER:
621 for( npc *them : followers ) {
622 them->rules.set_danger_overrides();
623 }
624 yell_msg = _( "We're in danger. Stay awake, stay close, don't go wandering off, "
625 "and don't open any doors." );
626 break;
628 for( npc *p : followers ) {
630 }
631 yell_msg = _( "As you were." );
632 break;
633 case NPC_CHAT_ORDERS:
634 npc_temp_orders_menu( followers );
635 break;
638 break;
641 break;
644 break;
647 break;
648 default:
649 return;
650 }
651
652 if( !yell_msg.empty() ) {
653 message = string_format( "\"%s\"", yell_msg );
654 }
655 if( !message.empty() ) {
656 add_msg( _( "You yell %s" ), message );
657 u.shout( string_format( _( "%s yelling %s" ), u.disp_name(), message ), is_order );
658 }
659
660 u.moves -= 100;
661}
std::string disp_name(bool possessive=false, bool capitalize_first=false) const override
Returns either "you" or the player's name.
Definition: character.cpp:580
void shout(std::string msg="", bool order=false)
Definition: character.cpp:7639
bool can_hear(const tripoint &source, int volume) const
bool is_wearing(const item &itm) const
Returns true if the player is wearing the item.
Definition: character.cpp:3235
bool has_trait(const trait_id &b) const override
Returns true if the player has the entered trait.
Definition: mutation.cpp:101
int get_shout_volume() const
Definition: character.cpp:7596
int moves
Definition: creature.h:582
std::optional< tripoint > look_around(bool force_3d=false)
Definition: game.cpp:6599
friend map & get_map()
Definition: map.cpp:148
Manage and cache data about a part of the map.
Definition: map.h:384
std::string companion_mission_role_id
Definition: npc.h:1283
npc_mission mission
Definition: npc.h:1290
bool is_player_ally() const
Definition: npc.cpp:1991
bool is_following() const
Definition: npc.cpp:2022
Shows a window querying the user for input.
bool has_flag(const std::string &flag) const
Definition: veh_type.h:336
This is a wrapper over a vehicle pointer and a reference to a part of it.
coords::coord_point< tripoint, coords::origin::abs, coords::ms > tripoint_abs_ms
Definition: coordinates.h:486
int rl_dist(const coords::coord_point< Point, Origin, Scale > &loc1, const coords::coord_point< Point, Origin, Scale > &loc2)
Definition: coordinates.h:519
static constexpr int SEEX
auto here(const Character &you) -> elevator::tiles
std::string message
Definition: mapgen.cpp:420
std::string name(type dir)
Get Human readable name of a direction.
Definition: overmap.cpp:4140
void wake_up(npc &)
void find_mount(npc &)
void clear_overrides(npc &p)
void stop_guard(npc &)
void assign_guard(npc &)
quantity< int, volume_in_milliliter_tag > volume
Definition: units_volume.h:16
@ NPC_MISSION_GUARD_ALLY
Definition: npc.h:150
static const efftype_id effect_riding("riding")
static const trait_id trait_PROF_FOODP("PROF_FOODP")
static int npc_select_menu(const std::vector< npc * > &npc_list, const std::string &prompt, const bool everyone=true)
Definition: npctalk.cpp:223
static void tell_magic_veh_stop_following()
Definition: npctalk.cpp:380
static void tell_veh_stop_following()
Definition: npctalk.cpp:343
static void assign_veh_to_follow()
Definition: npctalk.cpp:354
static void npc_temp_orders_menu(const std::vector< npc * > &npc_list)
Definition: npctalk.cpp:255
static const itype_id fuel_type_animal("animal")
@ NPC_CHAT_MOUNT
Definition: npctalk.cpp:203
@ NPC_CHAT_COMMAND_MAGIC_VEHICLE_STOP_FOLLOW
Definition: npctalk.cpp:217
@ NPC_CHAT_YELL
Definition: npctalk.cpp:197
@ NPC_CHAT_FOLLOW
Definition: npctalk.cpp:200
@ NPC_CHAT_GUARD
Definition: npctalk.cpp:199
@ NPC_CHAT_DISMOUNT
Definition: npctalk.cpp:204
@ NPC_CHAT_ANIMAL_VEHICLE_FOLLOW
Definition: npctalk.cpp:214
@ NPC_CHAT_ORDERS
Definition: npctalk.cpp:206
@ NPC_CHAT_SENTENCE
Definition: npctalk.cpp:198
@ NPC_CHAT_CLEAR_OVERRIDES
Definition: npctalk.cpp:213
@ NPC_CHAT_DANGER
Definition: npctalk.cpp:205
@ NPC_CHAT_MOVE_TO_POS
Definition: npctalk.cpp:201
@ NPC_CHAT_AWAKE
Definition: npctalk.cpp:202
@ NPC_CHAT_ANIMAL_VEHICLE_STOP_FOLLOW
Definition: npctalk.cpp:215
@ NPC_CHAT_TALK
Definition: npctalk.cpp:196
@ NPC_CHAT_COMMAND_MAGIC_VEHICLE_FOLLOW
Definition: npctalk.cpp:216
static void tell_magic_veh_to_follow()
Definition: npctalk.cpp:364
int popup(const std::string &text, PopupFlags flags)
Definition: output.cpp:764

References _, add_msg(), player::add_msg_if_player(), uilist::addentry(), talk_function::assign_guard(), assign_veh_to_follow(), available, Character::can_hear(), talk_function::clear_overrides(), npc::companion_mission_role_id, Character::disp_name(), effect_riding, talk_function::find_mount(), fuel_type_animal, get_map, get_npcs_if(), Character::get_shout_volume(), map::get_vehicles(), vpart_info::has_flag(), Character::has_trait(), anonymous_namespace{iexamine_elevator.cpp}::elevator::here(), npc::is_following(), npc::is_player_ally(), Character::is_wearing(), look_around(), m, m_info, m_warning, mapgen_defer::message, npc::mission, Creature::moves, om_direction::name(), NPC_CHAT_ANIMAL_VEHICLE_FOLLOW, NPC_CHAT_ANIMAL_VEHICLE_STOP_FOLLOW, NPC_CHAT_AWAKE, NPC_CHAT_CLEAR_OVERRIDES, NPC_CHAT_COMMAND_MAGIC_VEHICLE_FOLLOW, NPC_CHAT_COMMAND_MAGIC_VEHICLE_STOP_FOLLOW, NPC_CHAT_DANGER, NPC_CHAT_DISMOUNT, NPC_CHAT_FOLLOW, NPC_CHAT_GUARD, NPC_CHAT_MOUNT, NPC_CHAT_MOVE_TO_POS, NPC_CHAT_ORDERS, NPC_CHAT_SENTENCE, NPC_CHAT_TALK, NPC_CHAT_YELL, NPC_MISSION_GUARD_ALLY, npc_select_menu(), npc_temp_orders_menu(), popup(), Character::pos(), Character::posz(), uilist::query(), uilist::ret, rl_dist(), Character::sees(), SEEX, Character::shout(), talk_function::stop_guard(), string_format(), tell_magic_veh_stop_following(), tell_magic_veh_to_follow(), tell_veh_stop_following(), uilist::text, trait_PROF_FOODP, u, and talk_function::wake_up().

Referenced by handle_action().

◆ check_near_zone()

bool game::check_near_zone ( const zone_type_id type,
const tripoint where 
) const

Checks whether or not there is a zone of particular type nearby.

Definition at line 6049 of file game.cpp.

6050{
6051 return zone_manager::get_manager().has_near( type, m.getabs( where ) );
6052}
static zone_manager & get_manager()
Definition: clzones.cpp:127
bool has_near(const zone_type_id &type, const tripoint &where, int range=MAX_DISTANCE, const faction_id &fac=your_fac) const
Definition: clzones.cpp:703

References zone_manager::get_manager(), map::getabs(), zone_manager::has_near(), m, and type.

◆ check_safe_mode_allowed()

bool game::check_safe_mode_allowed ( bool  repeat_safe_mode_warnings = true)

Check whether movement is allowed according to safe mode settings.

Returns
true if the movement is allowed, otherwise false.

Definition at line 8589 of file game.cpp.

8590{
8591 if( !repeat_safe_mode_warnings && safe_mode_warning_logged ) {
8592 // Already warned player since safe_mode_warning_logged is set.
8593 return false;
8594 }
8595
8596 std::string msg_ignore = press_x( ACTION_IGNORE_ENEMY );
8597 if( !msg_ignore.empty() ) {
8598 std::wstring msg_ignore_wide = utf8_to_wstr( msg_ignore );
8599 // Operate on a wide-char basis to prevent corrupted multi-byte string
8600 msg_ignore_wide[0] = towlower( msg_ignore_wide[0] );
8601 msg_ignore = wstr_to_utf8( msg_ignore_wide );
8602 }
8603
8605 // Automatic and mandatory safemode. Make BLOODY sure the player notices!
8606 if( u.get_int_base() < 5 || u.has_trait( trait_id( "PROF_CHURL" ) ) ) {
8608 _( "There's an angry red dot on your body, %s to brush it off." ), msg_ignore );
8609 } else {
8611 _( "You are being laser-targeted, %s to ignore." ), msg_ignore );
8612 }
8614 return false;
8615 }
8616 if( safe_mode != SAFE_MODE_STOP ) {
8617 return true;
8618 }
8619 // Currently driving around, ignore the monster, they have no chance against a proper car anyway (-:
8620 if( u.controlling_vehicle && !get_option<bool>( "SAFEMODEVEH" ) ) {
8621 return true;
8622 }
8623 // Monsters around and we don't want to run
8624 std::string spotted_creature_name;
8625 const monster_visible_info &mon_visible = u.get_mon_visible();
8626 const auto &new_seen_mon = mon_visible.new_seen_mon;
8627
8628 if( new_seen_mon.empty() ) {
8629 // naming consistent with code in game::mon_info
8630 spotted_creature_name = _( "a survivor" );
8632 } else {
8633 spotted_creature_name = new_seen_mon.back()->name();
8634 get_safemode().lastmon_whitelist = spotted_creature_name;
8635 }
8636
8637 std::string whitelist;
8638 if( !get_safemode().empty() ) {
8639 whitelist = string_format( _( " or %s to whitelist the monster" ),
8641 }
8642
8643 const std::string msg_safe_mode = press_x( ACTION_TOGGLE_SAFEMODE );
8645 _( "Spotted %1$s--safe mode is on! (%2$s to turn it off, %3$s to ignore monster%4$s)" ),
8646 spotted_creature_name, msg_safe_mode, msg_ignore, whitelist );
8648 return false;
8649}
std::string press_x(action_id act)
Definition: action.cpp:465
@ ACTION_IGNORE_ENEMY
Ignore the enemy that triggered safemode.
Definition: action.h:217
@ ACTION_WHITELIST_ENEMY
Whitelist the enemy that triggered safemode.
Definition: action.h:219
@ ACTION_TOGGLE_SAFEMODE
Turn safemode on/off, while leaving autosafemode intact.
Definition: action.h:211
std::wstring utf8_to_wstr(const std::string &str)
std::string wstr_to_utf8(const std::wstring &wstr)
bool has_effect(const efftype_id &eff_id, body_part bp=num_bp) const
Check if creature has the matching effect.
Definition: creature.cpp:1207
int get_int_base() const override
Definition: avatar.cpp:1023
monster_visible_info & get_mon_visible()
Definition: avatar.h:226
std::string lastmon_whitelist
Definition: safemode_ui.h:87
std::string npc_type_name()
Definition: safemode_ui.cpp:44
@ gmf_bypass_cooldown
Definition: enums.h:288
static const efftype_id effect_laserlocked("laserlocked")
@ SAFE_MODE_STOP
Definition: game.h:79
safemode & get_safemode()
Definition: safemode_ui.cpp:33
Structure allowing a combination of game_message_type and game_message_flags.
Definition: enums.h:293
std::vector< shared_ptr_fast< monster > > new_seen_mon
Definition: avatar.h:41

References _, ACTION_IGNORE_ENEMY, ACTION_TOGGLE_SAFEMODE, ACTION_WHITELIST_ENEMY, add_msg(), Character::controlling_vehicle, effect_laserlocked, avatar::get_int_base(), avatar::get_mon_visible(), get_safemode(), gmf_bypass_cooldown, Creature::has_effect(), Character::has_trait(), safemode::lastmon_whitelist, m_warning, monster_visible_info::new_seen_mon, safemode::npc_type_name(), press_x(), safe_mode, SAFE_MODE_STOP, safe_mode_warning_logged, string_format(), u, utf8_to_wstr(), and wstr_to_utf8().

Referenced by handle_action().

◆ check_zone()

bool game::check_zone ( const zone_type_id type,
const tripoint where 
) const

Definition at line 6044 of file game.cpp.

6045{
6046 return zone_manager::get_manager().has( type, m.getabs( where ) );
6047}
bool has(const zone_type_id &type, const tripoint &where, const faction_id &fac=your_fac) const
Definition: clzones.cpp:695

References zone_manager::get_manager(), map::getabs(), zone_manager::has(), m, and type.

Referenced by place_player().

◆ cleanup_at_end()

bool game::cleanup_at_end ( )

Definition at line 943 of file game.cpp.

944{
945 if( uquit == QUIT_DIED || uquit == QUIT_SUICIDE ) {
946 // Put (non-hallucinations) into the overmap so they are not lost.
947 for( monster &critter : all_monsters() ) {
948 despawn_monster( critter );
949 }
950 // Reset NPC factions and disposition
952 // Save the factions', missions and set the NPC's overmap coordinates
953 // Npcs are saved in the overmap.
954 save_factions_missions_npcs(); //missions need to be saved as they are global for all saves.
955 // save artifacts.
957
958 // and the overmap, and the local map.
959 save_maps(); //Omap also contains the npcs who need to be saved.
960 }
961
962 if( uquit == QUIT_DIED || uquit == QUIT_SUICIDE ) {
963 std::vector<std::string> vRip;
964
965 int iMaxWidth = 0;
966 int iNameLine = 0;
967 int iInfoLine = 0;
968
971 if( !( u.has_trait( trait_id( "CANNIBAL" ) ) || u.has_trait( trait_id( "PSYCHOPATH" ) ) ) ) {
972 vRip.emplace_back( " _______ ___" );
973 vRip.emplace_back( " < `/ |" );
974 vRip.emplace_back( " > _ _ (" );
975 vRip.emplace_back( " | |_) | |_) |" );
976 vRip.emplace_back( " | | \\ | | |" );
977 vRip.emplace_back( " ______.__%_| |_________ __" );
978 vRip.emplace_back( " _/ \\| |" );
979 iNameLine = vRip.size();
980 vRip.emplace_back( "| <" );
981 vRip.emplace_back( "| |" );
982 iMaxWidth = utf8_width( vRip.back() );
983 vRip.emplace_back( "| |" );
984 vRip.emplace_back( "|_____.-._____ __/|_________|" );
985 vRip.emplace_back( " | |" );
986 iInfoLine = vRip.size();
987 vRip.emplace_back( " | |" );
988 vRip.emplace_back( " | <" );
989 vRip.emplace_back( " | |" );
990 vRip.emplace_back( " | _ |" );
991 vRip.emplace_back( " |__/ |" );
992 vRip.emplace_back( " % / `--. |%" );
993 vRip.emplace_back( " * .%%| -< @%%%" ); // NOLINT(cata-text-style)
994 vRip.emplace_back( " `\\%`@| |@@%@%%" );
995 vRip.emplace_back( " .%%%@@@|% ` % @@@%%@%%%%" );
996 vRip.emplace_back( " _.%%%%%%@@@@@@%%%__/\\%@@%%@@@@@@@%%%%%%" );
997
998 } else {
999 vRip.emplace_back( " _______ ___" );
1000 vRip.emplace_back( " | \\/ |" );
1001 vRip.emplace_back( " | |" );
1002 vRip.emplace_back( " | |" );
1003 iInfoLine = vRip.size();
1004 vRip.emplace_back( " | |" );
1005 vRip.emplace_back( " | |" );
1006 vRip.emplace_back( " | |" );
1007 vRip.emplace_back( " | |" );
1008 vRip.emplace_back( " | <" );
1009 vRip.emplace_back( " | _ |" );
1010 vRip.emplace_back( " |__/ |" );
1011 vRip.emplace_back( " ______.__%_| |__________ _" );
1012 vRip.emplace_back( " _/ \\| \\" );
1013 iNameLine = vRip.size();
1014 vRip.emplace_back( "| <" );
1015 vRip.emplace_back( "| |" );
1016 iMaxWidth = utf8_width( vRip.back() );
1017 vRip.emplace_back( "| |" );
1018 vRip.emplace_back( "|_____.-._______ __/|__________|" );
1019 vRip.emplace_back( " % / `_-. _ |%" );
1020 vRip.emplace_back( " * .%%| |_) | |_)< @%%%" ); // NOLINT(cata-text-style)
1021 vRip.emplace_back( " `\\%`@| | \\ | | |@@%@%%" );
1022 vRip.emplace_back( " .%%%@@@|% ` % @@@%%@%%%%" );
1023 vRip.emplace_back( " _.%%%%%%@@@@@@%%%__/\\%@@%%@@@@@@@%%%%%%" );
1024 }
1025 } else {
1026 vRip.emplace_back( R"( _________ ____ )" );
1027 vRip.emplace_back( R"( _/ `/ \_ )" );
1028 vRip.emplace_back( R"( _/ _ _ \_. )" );
1029 vRip.emplace_back( R"( _%\ |_) | |_) \_ )" );
1030 vRip.emplace_back( R"( _/ \/ | \ | | \_ )" );
1031 vRip.emplace_back( R"( _/ \_ )" );
1032 vRip.emplace_back( R"(| |)" );
1033 iNameLine = vRip.size();
1034 vRip.emplace_back( R"( ) < )" );
1035 vRip.emplace_back( R"(| |)" );
1036 vRip.emplace_back( R"(| |)" );
1037 vRip.emplace_back( R"(| _ |)" );
1038 vRip.emplace_back( R"(|__/ |)" );
1039 iMaxWidth = utf8_width( vRip.back() );
1040 vRip.emplace_back( R"( / `--. |)" );
1041 vRip.emplace_back( R"(| ( )" );
1042 iInfoLine = vRip.size();
1043 vRip.emplace_back( R"(| |)" );
1044 vRip.emplace_back( R"(| |)" );
1045 vRip.emplace_back( R"(| % . |)" );
1046 vRip.emplace_back( R"(| @` %% |)" );
1047 vRip.emplace_back( R"(| %@%@%\ * %`%@%|)" );
1048 vRip.emplace_back( R"(%%@@@.%@%\%% `\ %%.%%@@%@)" );
1049 vRip.emplace_back( R"(@%@@%%%%%@@@@@@%%%%%%%%@@%%@@@%%%@%%@)" );
1050 }
1051
1052 const int iOffsetX = TERMX > FULL_SCREEN_WIDTH ? ( TERMX - FULL_SCREEN_WIDTH ) / 2 : 0;
1053 const int iOffsetY = TERMY > FULL_SCREEN_HEIGHT ? ( TERMY - FULL_SCREEN_HEIGHT ) / 2 : 0;
1054
1056 point( iOffsetX, iOffsetY ) );
1057 draw_border( w_rip );
1058
1059 sfx::do_player_death_hurt( g->u, true );
1064
1065 for( size_t iY = 0; iY < vRip.size(); ++iY ) {
1066 size_t iX = 0;
1067 const char *str = vRip[iY].data();
1068 for( int slen = vRip[iY].size(); slen > 0; ) {
1069 const uint32_t cTemp = UTF8_getch( &str, &slen );
1070 if( cTemp != U' ' ) {
1071 nc_color ncColor = c_light_gray;
1072
1073 if( cTemp == U'%' ) {
1074 ncColor = c_green;
1075
1076 } else if( cTemp == U'_' || cTemp == U'|' ) {
1077 ncColor = c_white;
1078
1079 } else if( cTemp == U'@' ) {
1080 ncColor = c_brown;
1081
1082 } else if( cTemp == U'*' ) {
1083 ncColor = c_red;
1084 }
1085
1086 mvwputch( w_rip, point( iX + FULL_SCREEN_WIDTH / 2 - ( iMaxWidth / 2 ), iY + 1 ), ncColor,
1087 cTemp );
1088 }
1089 iX += mk_wcwidth( cTemp );
1090 }
1091 }
1092
1093 std::string sTemp;
1094
1095 center_print( w_rip, iInfoLine++, c_white, _( "Survived:" ) );
1096
1098 const int minutes = to_minutes<int>( survived ) % 60;
1099 const int hours = to_hours<int>( survived ) % 24;
1100 const int days = to_days<int>( survived );
1101
1102 if( days > 0 ) {
1103 sTemp = string_format( "%dd %dh %dm", days, hours, minutes );
1104 } else if( hours > 0 ) {
1105 sTemp = string_format( "%dh %dm", hours, minutes );
1106 } else {
1107 sTemp = string_format( "%dm", minutes );
1108 }
1109
1110 center_print( w_rip, iInfoLine++, c_white, sTemp );
1111
1112 const int iTotalKills = get_kill_tracker().monster_kill_count();
1113
1114 sTemp = _( "Kills:" );
1115 mvwprintz( w_rip, point( FULL_SCREEN_WIDTH / 2 - 5, 1 + iInfoLine++ ), c_light_gray,
1116 ( sTemp + " " ) );
1117 wprintz( w_rip, c_magenta, "%d", iTotalKills );
1118
1119 sTemp = _( "In memory of:" );
1120 mvwprintz( w_rip, point( FULL_SCREEN_WIDTH / 2 - utf8_width( sTemp ) / 2, iNameLine++ ),
1122 sTemp );
1123
1124 sTemp = u.name;
1125 mvwprintz( w_rip, point( FULL_SCREEN_WIDTH / 2 - utf8_width( sTemp ) / 2, iNameLine++ ), c_white,
1126 sTemp );
1127
1128 sTemp = _( "Last Words:" );
1129 mvwprintz( w_rip, point( FULL_SCREEN_WIDTH / 2 - utf8_width( sTemp ) / 2, iNameLine++ ),
1131 sTemp );
1132
1133 int iStartX = FULL_SCREEN_WIDTH / 2 - ( ( iMaxWidth - 4 ) / 2 );
1134 std::string sLastWords = string_input_popup()
1135 .window( w_rip, point( iStartX, iNameLine ), iStartX + iMaxWidth - 4 - 1 )
1136 .max_length( iMaxWidth - 4 - 1 )
1137 .query_string();
1138 death_screen();
1139 const bool is_suicide = uquit == QUIT_SUICIDE;
1140 events().send<event_type::game_over>( is_suicide, sLastWords );
1141 // Struck the save_player_data here to forestall Weirdness
1142 std::string char_filename = generate_memorial_filename( u.name );
1143 move_save_to_graveyard( char_filename );
1144 write_memorial_file( char_filename, sLastWords );
1145 memorial().clear();
1146 std::vector<std::string> characters = list_active_saves();
1147 // remove current player from the active characters list, as they are dead
1148 std::vector<std::string>::iterator curchar = std::find( characters.begin(),
1149 characters.end(), u.get_save_id() );
1150 if( curchar != characters.end() ) {
1151 characters.erase( curchar );
1152 }
1153
1154 if( characters.empty() ) {
1155 bool queryDelete = false;
1156 bool queryReset = false;
1157
1158 if( get_option<std::string>( "WORLD_END" ) == "query" ) {
1159 bool decided = false;
1160 std::string buffer = _( "Warning: NPC interactions and some other global flags "
1161 "will not all reset when starting a new character in an "
1162 "already-played world. This can lead to some strange "
1163 "behavior.\n\n"
1164 "Are you sure you wish to keep this world?"
1165 );
1166
1167 while( !decided ) {
1168 uilist smenu;
1169 smenu.allow_cancel = false;
1170 smenu.addentry( 0, true, 'r', "%s", _( "Reset world" ) );
1171 smenu.addentry( 1, true, 'd', "%s", _( "Delete world" ) );
1172 smenu.addentry( 2, true, 'k', "%s", _( "Keep world" ) );
1173 smenu.query();
1174
1175 switch( smenu.ret ) {
1176 case 0:
1177 queryReset = true;
1178 decided = true;
1179 break;
1180 case 1:
1181 queryDelete = true;
1182 decided = true;
1183 break;
1184 case 2:
1185 decided = query_yn( buffer );
1186 break;
1187 }
1188 }
1189 }
1190
1191 if( queryDelete || get_option<std::string>( "WORLD_END" ) == "delete" ) {
1192 world_generator->delete_world( world_generator->active_world->world_name, true );
1193
1194 } else if( queryReset || get_option<std::string>( "WORLD_END" ) == "reset" ) {
1195 world_generator->delete_world( world_generator->active_world->world_name, false );
1196 }
1197 } else if( get_option<std::string>( "WORLD_END" ) != "keep" ) {
1198 std::string tmpmessage;
1199 for( auto &character : characters ) {
1200 tmpmessage += "\n ";
1201 tmpmessage += character;
1202 }
1203 popup( _( "World retained. Characters remaining:%s" ), tmpmessage );
1204 }
1205 if( gamemode ) {
1206 gamemode = std::make_unique<special_game>(); // null gamemode or something..
1207 }
1208 }
1209
1210 //Reset any offset due to driving
1212
1213 //clear all sound channels
1219
1220 MAPBUFFER.clear();
1222
1223#if defined(__ANDROID__)
1224 quick_shortcuts_map.clear();
1225#endif
1226 return true;
1227}
uint32_t UTF8_getch(const char **src, int *srclen)
Definition: catacharset.cpp:18
int utf8_width(const char *s, const bool ignore_tags)
std::string name
Definition: character.h:1564
std::string get_save_id() const
Definition: avatar.h:88
A wrapper over a pointer to a curses window.
Definition: cursesdef.h:55
void send(const cata::event &) const
Definition: event_bus.cpp:58
void move_save_to_graveyard(const std::string &dirname)
Definition: game.cpp:2471
bool save_maps()
Definition: game.cpp:2674
std::unique_ptr< special_game > gamemode
Definition: game.h:1054
void death_screen()
Definition: game.cpp:2420
monster_range all_monsters()
Same as all_creatures but iterators only over monsters.
Definition: game.cpp:12041
bool save_factions_missions_npcs()
Definition: game.cpp:2660
void despawn_monster(monster &critter)
Despawn a specific monster, it's stored on the overmap.
Definition: game.cpp:11050
void write_memorial_file(const std::string &filename, std::string sLastWords)
Writes information about the character out to a text file timestamped with the time of the file was m...
Definition: game.cpp:2789
std::vector< std::string > list_active_saves()
Returns a list of currently active character saves.
Definition: game.cpp:2774
bool save_artifacts()
Definition: game.cpp:2668
kill_tracker & get_kill_tracker()
Definition: game.cpp:2723
memorial_logger & memorial()
Definition: game.cpp:2728
void reset_npc_dispositions()
Definition: game.cpp:2632
int monster_kill_count() const
void clear()
Delete all buffered submaps.
Definition: mapbuffer.cpp:45
string_input_popup & window(const catacurses::window &w, point start, int endx)
Set the window area where to display the input text.
string_input_popup & max_length(int value)
Maximal amount of Unicode characters that can be given by the user.
const std::string & query_string(bool loop=true, bool draw_only=false)
A duration defined as a number of specific time units.
Definition: calendar.h:180
bool allow_cancel
Definition: ui.h:362
bool has_amount(const itype_id &what, int qty, bool pseudo=true, const std::function< bool(const item &)> &filter=return_true< item >) const
Check instance provides at least qty of an item (.
Definition: visitable.cpp:1112
#define c_white
Definition: color.h:18
#define c_light_gray
Definition: color.h:19
#define c_green
Definition: color.h:22
#define c_magenta
Definition: color.h:25
#define c_brown
Definition: color.h:26
#define c_red
Definition: color.h:21
static const itype_id itype_holybook_bible1("holybook_bible1")
static std::string generate_memorial_filename(const std::string &char_name)
Definition: game.cpp:916
static const itype_id itype_holybook_bible2("holybook_bible2")
static const itype_id itype_holybook_bible3("holybook_bible3")
std::unique_ptr< game > g
Definition: game.cpp:285
@ QUIT_DIED
Definition: game.h:72
@ QUIT_SUICIDE
Definition: game.h:69
const time_point & start_of_cataclysm
Definition: calendar.cpp:33
window newwin(int nlines, int ncols, point begin)
Definition: ncurses_def.cpp:35
FMT_CONSTEXPR bool find(Ptr first, Ptr last, T value, Ptr &out)
const size_t size
Definition: om_direction.h:28
void do_player_death_hurt(const player &target, bool death)
Definition: sounds.cpp:1632
void fade_audio_channel(channel channel, int duration)
Definition: sounds.cpp:1617
void fade_audio_group(group group, int duration)
Definition: sounds.cpp:1616
int TERMX
Definition: output.cpp:47
void mvwprintz(const catacurses::window &w, point p, const nc_color &FG, const std::string &text)
Definition: output.cpp:2081
int FULL_SCREEN_HEIGHT
Definition: output.cpp:56
int TERMY
Definition: output.cpp:48
void center_print(const catacurses::window &w, const int y, const nc_color &FG, const std::string &text)
Definition: output.cpp:446
void mvwputch(const catacurses::window &w, point p, nc_color FG, int ch)
Definition: output.cpp:477
void wprintz(const catacurses::window &w, const nc_color &FG, const std::string &text)
Definition: output.cpp:2089
int FULL_SCREEN_WIDTH
Definition: output.cpp:55
void draw_border(const catacurses::window &w, nc_color border_color, const std::string &title, nc_color title_color)
Definition: output.cpp:575
overmapbuffer overmap_buffer
int mk_wcwidth(uint32_t ucs)
Definition: wcwidth.cpp:94

References _, uilist::addentry(), all_monsters(), uilist::allow_cancel, sfx::any, c_brown, c_green, c_light_gray, c_magenta, c_red, c_white, center_print(), mapbuffer::clear(), memorial_logger::clear(), overmapbuffer::clear(), sfx::context_themes, death_screen(), despawn_monster(), sfx::do_player_death_hurt(), draw_border(), events(), sfx::fade_audio_channel(), sfx::fade_audio_group(), sfx::fatigue, detail::find(), FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH, g, game_over, gamemode, generate_memorial_filename(), get_kill_tracker(), avatar::get_save_id(), visitable< T >::has_amount(), Character::has_trait(), itype_holybook_bible1, itype_holybook_bible2, itype_holybook_bible3, list_active_saves(), MAPBUFFER, string_input_popup::max_length(), memorial(), mk_wcwidth(), kill_tracker::monster_kill_count(), move_save_to_graveyard(), mvwprintz(), mvwputch(), Character::name, catacurses::newwin(), overmap_buffer, point_zero, popup(), uilist::query(), string_input_popup::query_string(), query_yn(), QUIT_DIED, QUIT_SUICIDE, reset_npc_dispositions(), uilist::ret, save_artifacts(), save_factions_missions_npcs(), save_maps(), event_bus::send(), set_driving_view_offset(), om_direction::size, calendar::start_of_cataclysm, string_format(), TERMX, TERMY, sfx::time_of_day, calendar::turn, u, uquit, UTF8_getch(), utf8_width(), sfx::weather, string_input_popup::window(), world_generator, wprintz(), and write_memorial_file().

Referenced by do_turn().

◆ cleanup_dead()

void game::cleanup_dead ( )

Definition at line 4043 of file game.cpp.

4044{
4045 // Dead monsters need to stay in the tracker until everything else that needs to die does so
4046 // This is because dying monsters can still interact with other dying monsters (@ref Creature::killer)
4047 bool monster_is_dead = critter_tracker->kill_marked_for_death();
4048
4049 bool npc_is_dead = false;
4050 // can't use all_npcs as that does not include dead ones
4051 for( const auto &n : active_npc ) {
4052 if( n->is_dead() ) {
4053 n->die( nullptr ); // make sure this has been called to create corpses etc.
4054 npc_is_dead = true;
4055 }
4056 }
4057
4058 if( monster_is_dead ) {
4059 // From here on, pointers to creatures get invalidated as dead creatures get removed.
4060 critter_tracker->remove_dead();
4061 }
4062
4063 if( npc_is_dead ) {
4064 for( auto it = active_npc.begin(); it != active_npc.end(); ) {
4065 if( ( *it )->is_dead() ) {
4066 remove_npc_follower( ( *it )->getID() );
4067 overmap_buffer.remove_npc( ( *it )->getID() );
4068 it = active_npc.erase( it );
4069 } else {
4070 it++;
4071 }
4072 }
4073 }
4074
4075 critter_died = false;
4076}
void remove_npc_follower(const character_id &id)
Remove follower id from follower set.
Definition: game.cpp:1880
pimpl< Creature_tracker > critter_tracker
Definition: game.h:972
std::list< shared_ptr_fast< npc > > active_npc
Definition: game.h:1036
bool critter_died
Has anything died in this turn and needs to be cleaned up?
Definition: game.h:1048
shared_ptr_fast< npc > remove_npc(const character_id &id)
Find npc by id and if found, erase it from the npc list and return it ( or return nullptr if not foun...

References active_npc, critter_died, critter_tracker, overmap_buffer, overmapbuffer::remove_npc(), and remove_npc_follower().

Referenced by do_turn(), and monmove().

◆ clear_zombies()

void game::clear_zombies ( )

Redirects to the creature_tracker clear() function.

Definition at line 4739 of file game.cpp.

4740{
4741 critter_tracker->clear();
4742}

References critter_tracker.

Referenced by setup().

◆ control_vehicle()

void game::control_vehicle ( )
private

Definition at line 5183 of file game.cpp.

5184{
5185 static const itype_id fuel_type_animal( "animal" );
5186 int veh_part = -1;
5187 vehicle *veh = remoteveh();
5188 if( veh == nullptr ) {
5189 if( const optional_vpart_position vp = m.veh_at( u.pos() ) ) {
5190 veh = &vp->vehicle();
5191 veh_part = vp->part_index();
5192 }
5193 }
5194 if( veh != nullptr && veh->player_in_control( u ) &&
5195 veh->avail_part_with_feature( veh_part, "CONTROLS", true ) >= 0 ) {
5196 veh->use_controls( u.pos() );
5197 } else if( veh && veh->player_in_control( u ) &&
5198 veh->avail_part_with_feature( veh_part, "CONTROL_ANIMAL", true ) >= 0 ) {
5199 u.controlling_vehicle = false;
5200 add_msg( m_info, _( "You let go of the reins." ) );
5201 } else if( veh && ( veh->avail_part_with_feature( veh_part, "CONTROLS", true ) >= 0 ||
5202 ( veh->avail_part_with_feature( veh_part, "CONTROL_ANIMAL", true ) >= 0 &&
5203 veh->has_engine_type( fuel_type_animal, false ) && veh->has_harnessed_animal() ) ) &&
5204 u.in_vehicle ) {
5205 if( u.has_trait( trait_WAYFARER ) ) {
5206 add_msg( m_info, _( "You refuse to take control of this vehicle." ) );
5207 return;
5208 }
5209 if( !veh->interact_vehicle_locked() ) {
5210 veh->handle_potential_theft( u );
5211 return;
5212 }
5213 if( veh->engine_on ) {
5214 if( !veh->handle_potential_theft( u ) ) {
5215 return;
5216 }
5217 u.controlling_vehicle = true;
5218 add_msg( _( "You take control of the %s." ), veh->name );
5219 } else {
5220 if( !veh->handle_potential_theft( u ) ) {
5221 return;
5222 }
5223 veh->start_engines( true );
5224 }
5225 } else { // Start looking for nearby vehicle controls.
5226 int num_valid_controls = 0;
5227 std::optional<tripoint> vehicle_position;
5228 std::optional<vpart_reference> vehicle_controls;
5229 for( const tripoint elem : m.points_in_radius( g->u.pos(), 1 ) ) {
5230 if( const optional_vpart_position vp = m.veh_at( elem ) ) {
5231 const std::optional<vpart_reference> controls = vp.value().part_with_feature( "CONTROLS", true );
5232 if( controls ) {
5233 num_valid_controls++;
5234 vehicle_position = elem;
5235 vehicle_controls = controls;
5236 }
5237 }
5238 }
5239 if( num_valid_controls < 1 ) {
5240 add_msg( _( "No vehicle controls found." ) );
5241 return;
5242 } else if( num_valid_controls > 1 ) {
5243 vehicle_position = choose_adjacent( _( "Control vehicle where?" ) );
5244 if( !vehicle_position ) {
5245 return;
5246 }
5247 const optional_vpart_position vp = m.veh_at( *vehicle_position );
5248 if( vp ) {
5249 vehicle_controls = vp.value().part_with_feature( "CONTROLS", true );
5250 if( !vehicle_controls ) {
5251 add_msg( _( "The vehicle doesn't have controls there." ) );
5252 return;
5253 }
5254 } else {
5255 add_msg( _( "No vehicle there." ) );
5256 return;
5257 }
5258 }
5259 // If we hit neither of those, there's only one set of vehicle controls, which should already have been found.
5260 if( vehicle_controls ) {
5261 veh = &vehicle_controls->vehicle();
5262 if( !veh->handle_potential_theft( u ) ) {
5263 return;
5264 }
5265 veh->use_controls( *vehicle_position );
5266 //May be folded up (destroyed), so need to re-get it
5267 veh = g->remoteveh();
5268 }
5269 }
5270 if( veh ) {
5271 // If we reached here, we gained control of a vehicle.
5272 // Clear the map memory for the area covered by the vehicle to eliminate ghost vehicles.
5273 for( const tripoint &target : veh->get_points() ) {
5274 u.clear_memorized_tile( m.getabs( target ) );
5275 }
5276 veh->is_following = false;
5277 veh->is_patrolling = false;
5278 veh->autopilot_on = false;
5279 veh->is_autodriving = false;
5280 }
5281}
std::optional< tripoint > choose_adjacent(const std::string &message, const bool allow_vertical)
Request player input of adjacent tile, possibly including vertical tiles.
Definition: action.cpp:988
bool in_vehicle
Definition: character.h:1571
void clear_memorized_tile(const tripoint &pos)
Definition: avatar.cpp:169
vehicle * remoteveh()
Returns the current remotely controlled vehicle.
Definition: game.cpp:2250
tripoint_range< tripoint > points_in_radius(const tripoint &center, size_t radius, size_t radiusz=0) const
Definition: map.cpp:8762
optional_vpart_position veh_at(const tripoint &p) const
Checks if tile is occupied by vehicle and by which part.
Definition: map.cpp:1074
Simple wrapper to forward functions that may return a std::optional to vpart_position.
std::optional< vpart_reference > part_with_feature(const std::string &f, bool unbroken) const
Definition: vehicle.cpp:2483
bool engine_on
Definition: vehicle.h:1721
std::set< tripoint > & get_points(bool force_refresh=false)
Definition: vehicle.cpp:6783
std::string name
Definition: vehicle.h:1581
bool has_engine_type(const itype_id &ft, bool enabled) const
Definition: vehicle.cpp:1033
void start_engines(bool take_control=false, bool autodrive=false)
void use_controls(const tripoint &pos)
Operate vehicle controls.
vehicle(const vproto_id &type_id, int init_veh_fuel=-1, int init_veh_status=-1)
Definition: vehicle.cpp:253
bool has_harnessed_animal() const
bool interact_vehicle_locked()
int avail_part_with_feature(int p, const std::string &f, bool unbroken) const
Definition: vehicle.cpp:2547
bool autopilot_on
Definition: vehicle.h:1729
bool is_autodriving
Definition: vehicle.h:1714
bool handle_potential_theft(avatar &you, bool check_only=false, bool prompt=true)
Handle potential vehicle theft.
Definition: vehicle.cpp:4409
static const trait_id trait_WAYFARER("WAYFARER")

References _, add_msg(), vehicle::autopilot_on, vehicle::avail_part_with_feature(), choose_adjacent(), avatar::clear_memorized_tile(), Character::controlling_vehicle, vehicle::engine_on, fuel_type_animal, g, vehicle::get_points(), map::getabs(), vehicle::handle_potential_theft(), vehicle::has_engine_type(), vehicle::has_harnessed_animal(), Character::has_trait(), Character::in_vehicle, vehicle::interact_vehicle_locked(), vehicle::is_autodriving, vehicle::is_following, vehicle::is_patrolling, m, m_info, vehicle::name, optional_vpart_position::part_with_feature(), vehicle::player_in_control(), map::points_in_radius(), Character::pos(), remoteveh(), vehicle::start_engines(), trait_WAYFARER, u, vehicle::use_controls(), map::veh_at(), and vehicle::vehicle().

Referenced by handle_action().

◆ create_or_get_main_ui_adaptor()

shared_ptr_fast< ui_adaptor > game::create_or_get_main_ui_adaptor ( )

In tiles mode w_terrain can have a different font (with a different tile dimension) or can be drawn by cata_tiles which uses tiles that again might have a different dimension then the normal font used everywhere else.

TERRAIN_WINDOW_WIDTH/TERRAIN_WINDOW_HEIGHT defines how many squares can be displayed in w_terrain (using it's specific tile dimension), not including partially drawn squares at the right/bottom. You should use it whenever you want to draw specific squares in that window or to determine whether a specific square is draw on screen (or outside the screen and needs scrolling).

TERRAIN_WINDOW_TERM_WIDTH/TERRAIN_WINDOW_TERM_HEIGHT defines the size of w_terrain in the standard font dimension (the font that everything else uses). You usually don't have to use it, expect for positioning of windows, because the window positions use the standard font dimension.

The code here calculates size available for w_terrain, caps it at max_view_size (the maximal view range than any character can have at any time). It is stored in TERRAIN_WINDOW_*.

Definition at line 2926 of file game.cpp.

2927{
2929 if( !ui ) {
2930 main_ui_adaptor = ui = make_shared_fast<ui_adaptor>();
2931 ui->on_redraw( []( const ui_adaptor & ) {
2932 g->draw();
2933 } );
2934 ui->on_screen_resize( [this]( ui_adaptor & ui ) {
2935 // remove some space for the sidebar, this is the maximal space
2936 // (using standard font) that the terrain window can have
2937 const int sidebar_left = panel_manager::get_manager().get_width_left();
2938 const int sidebar_right = panel_manager::get_manager().get_width_right();
2939
2941 TERRAIN_WINDOW_WIDTH = TERMX - ( sidebar_left + sidebar_right );
2944
2945 /**
2946 * In tiles mode w_terrain can have a different font (with a different
2947 * tile dimension) or can be drawn by cata_tiles which uses tiles that again
2948 * might have a different dimension then the normal font used everywhere else.
2949 *
2950 * TERRAIN_WINDOW_WIDTH/TERRAIN_WINDOW_HEIGHT defines how many squares can
2951 * be displayed in w_terrain (using it's specific tile dimension), not
2952 * including partially drawn squares at the right/bottom. You should
2953 * use it whenever you want to draw specific squares in that window or to
2954 * determine whether a specific square is draw on screen (or outside the screen
2955 * and needs scrolling).
2956 *
2957 * TERRAIN_WINDOW_TERM_WIDTH/TERRAIN_WINDOW_TERM_HEIGHT defines the size of
2958 * w_terrain in the standard font dimension (the font that everything else uses).
2959 * You usually don't have to use it, expect for positioning of windows,
2960 * because the window positions use the standard font dimension.
2961 *
2962 * The code here calculates size available for w_terrain, caps it at
2963 * max_view_size (the maximal view range than any character can have at
2964 * any time).
2965 * It is stored in TERRAIN_WINDOW_*.
2966 */
2968
2969 // Position of the player in the terrain window, it is always in the center
2972
2974 point( sidebar_left, 0 ) );
2975
2976 // minimap is always MINIMAP_WIDTH x MINIMAP_HEIGHT in size
2978
2979 // need to init in order to avoid crash. gets updated by the panel code.
2981
2982 ui.position_from_window( catacurses::stdscr );
2983 } );
2984 ui->mark_resize();
2985 }
2986 return ui;
2987}
catacurses::window w_pixel_minimap
Definition: game.h:990
catacurses::window w_minimap_ptr
Definition: game.h:1027
weak_ptr_fast< ui_adaptor > main_ui_adaptor
Definition: game.h:1073
catacurses::window w_minimap
Definition: game.h:989
catacurses::window w_terrain_ptr
Definition: game.h:1026
static panel_manager & get_manager()
Definition: panels.h:72
int get_width_right()
Definition: panels.cpp:2186
int get_width_left()
Definition: panels.cpp:2194
Adaptor between UI code and the UI management system.
Definition: ui_manager.h:65
static constexpr int MINIMAP_WIDTH
static constexpr int MINIMAP_HEIGHT
void to_map_font_dimension(int &, int &)
Definition: game_ui.cpp:20
std::shared_ptr< T > shared_ptr_fast
Definition: memory_fast.h:16
window stdscr
Definition: overmap_ui.h:17
int TERRAIN_WINDOW_TERM_WIDTH
Definition: output.cpp:53
int TERRAIN_WINDOW_TERM_HEIGHT
Definition: output.cpp:54
int POSX
Definition: output.cpp:49
int TERRAIN_WINDOW_WIDTH
Definition: output.cpp:51
int POSY
Definition: output.cpp:50
int TERRAIN_WINDOW_HEIGHT
Definition: output.cpp:52

References g, panel_manager::get_manager(), panel_manager::get_width_left(), panel_manager::get_width_right(), main_ui_adaptor, MINIMAP_HEIGHT, MINIMAP_WIDTH, catacurses::newwin(), point_zero, POSX, POSY, catacurses::stdscr, TERMX, TERMY, TERRAIN_WINDOW_HEIGHT, TERRAIN_WINDOW_TERM_HEIGHT, TERRAIN_WINDOW_TERM_WIDTH, TERRAIN_WINDOW_WIDTH, to_map_font_dimension(), w_minimap, w_minimap_ptr, w_pixel_minimap, w_terrain, and w_terrain_ptr.

◆ create_starting_npcs()

void game::create_starting_npcs ( )
private

Definition at line 887 of file game.cpp.

888{
889 if( !get_option<bool>( "STATIC_NPC" ) ||
890 get_option<std::string>( "STARTING_NPC" ) == "never" ) {
891 return; //Do not generate a starting npc.
892 }
893
894 //We don't want more than one starting npc per starting location
895 const int radius = 1;
896 if( !overmap_buffer.get_npcs_near_player( radius ).empty() ) {
897 return; //There is already an NPC in this starting location
898 }
899
900 shared_ptr_fast<npc> tmp = make_shared_fast<npc>();
901 tmp->randomize( one_in( 2 ) ? NC_DOCTOR : NC_NONE );
902 tmp->spawn_at_precise( { get_levx(), get_levy() }, u.pos() - point_south_east );
904 tmp->form_opinion( u );
905 tmp->set_attitude( NPCATT_NULL );
906 //This sets the NPC mission. This NPC remains in the starting location.
907 tmp->mission = NPC_MISSION_SHELTER;
908 tmp->chatbin.first_topic = "TALK_SHELTER";
909 tmp->toggle_trait( trait_id( "NPC_STARTING_NPC" ) );
910 tmp->set_fac( faction_id( "no_faction" ) );
911 //One random starting NPC mission
912 tmp->add_new_mission( mission::reserve_random( ORIGIN_OPENER_NPC, tmp->global_omt_location(),
913 tmp->getID() ) );
914}
int get_levy() const
Definition: game.cpp:11931
int get_levx() const
The top left corner of the reality bubble (in submaps coordinates).
Definition: game.cpp:11926
static mission * reserve_random(mission_origin origin, const tripoint_abs_omt &p, const character_id &npc_id)
Definition: mission.cpp:200
std::vector< shared_ptr_fast< npc > > get_npcs_near_player(int radius)
Same as get_npcs_near(int,int,int,int) but uses player position as center.
void insert_npc(const shared_ptr_fast< npc > &who)
Adds the npc to an overmap ( based on the npcs current location ) and stores it there.
string_id< faction > faction_id
Definition: clzones.h:30
@ ORIGIN_OPENER_NPC
Definition: mission.h:45
@ NPCATT_NULL
Definition: npc.h:81
@ NPC_MISSION_SHELTER
Definition: npc.h:144
npc_class_id NC_NONE("NC_NONE")
npc_class_id NC_DOCTOR("NC_DOCTOR")
static constexpr point point_south_east
Definition: point.h:265
bool one_in(int chance)
Definition: rng.cpp:65

References get_levx(), get_levy(), overmapbuffer::get_npcs_near_player(), overmapbuffer::insert_npc(), NC_DOCTOR, NC_NONE, NPC_MISSION_SHELTER, NPCATT_NULL, one_in(), ORIGIN_OPENER_NPC, overmap_buffer, point_south_east, Character::pos(), mission::reserve_random(), trait_id, and u.

Referenced by start_game().

◆ critter_at() [1/2]

template<typename T >
T * game::critter_at ( const tripoint p,
bool  allow_hallucination = false 
)

Returns the Creature at the given location.

Optionally casted to the given type of creature: npc, player, monster - if there is a creature, but it's not of the requested type, returns nullptr.

Parameters
allow_hallucinationWhether to return monsters that are actually hallucinations.

Definition at line 4544 of file game.cpp.

4545{
4546 if( const shared_ptr_fast<monster> mon_ptr = critter_tracker->find( p ) ) {
4547 if( !allow_hallucination && mon_ptr->is_hallucination() ) {
4548 return nullptr;
4549 }
4550 // if we wanted to check for an NPC / player / avatar,
4551 // there is sometimes a monster AND an NPC/player there at the same time.
4552 // because the NPC/player etc may be riding that monster.
4553 // so only return the monster if we were actually looking for a monster.
4554 // otherwise, keep looking for the rider.
4555 // critter_at<creature> or critter_at() with no template will still default to returning monster first,
4556 // which is ok for the occasions where that happens.
4557 if( !mon_ptr->has_effect( effect_ridden ) || ( std::is_same<T, monster>::value ||
4558 std::is_same<T, Creature>::value || std::is_same<T, const monster>::value ||
4559 std::is_same<T, const Creature>::value ) ) {
4560 return dynamic_cast<T *>( mon_ptr.get() );
4561 }
4562 }
4563 if( !std::is_same<T, npc>::value && !std::is_same<T, const npc>::value ) {
4564 if( p == u.pos() ) {
4565 return dynamic_cast<T *>( &u );
4566 }
4567 }
4568 for( auto &cur_npc : active_npc ) {
4569 if( cur_npc->pos() == p && !cur_npc->is_dead() ) {
4570 return dynamic_cast<T *>( cur_npc.get() );
4571 }
4572 }
4573 return nullptr;
4574}
static const efftype_id effect_ridden("ridden")

References active_npc, critter_tracker, effect_ridden, Character::pos(), and u.

Referenced by draw_look_around_cursor(), examine(), find_or_make_stairs(), fling_creature(), forced_door_closing(), get_player_input(), is_empty(), knockback(), phasing_move(), print_all_tile_info(), spawn_hallucination(), swap_critters(), and update_stair_monsters().

◆ critter_at() [2/2]

template<typename T >
const T * game::critter_at ( const tripoint p,
bool  allow_hallucination = false 
) const

Definition at line 4577 of file game.cpp.

4578{
4579 return const_cast<game *>( this )->critter_at<T>( p, allow_hallucination );
4580}
Definition: game.h:144

◆ critter_by_id()

template<typename T >
template Creature * game::critter_by_id< Creature > ( const character_id id)
Returns
The living creature with the given id. Returns null if no living creature with such an id exists. Never returns a dead creature. Currently only the player character and npcs have ids.

Definition at line 4623 of file game.cpp.

4624{
4625 if( id == u.getID() ) {
4626 // player is always alive, therefore no is-dead check
4627 return dynamic_cast<T *>( &u );
4628 }
4629 return find_npc( id );
4630}
character_id getID() const
Definition: character.cpp:494
npc * find_npc(character_id id)
Find the npc with the given ID.
Definition: game.cpp:1869

References find_npc(), Character::getID(), and u.

◆ death_screen()

void game::death_screen ( )
private

Definition at line 2420 of file game.cpp.

2421{
2422 gamemode->game_over();
2427 follower_ids.clear();
2429}
diary * get_avatar_diary()
Definition: avatar.cpp:370
void death_entry()
Definition: diary.cpp:672
stats_tracker & stats()
Definition: game.cpp:2718
void disp_NPC_epilogues()
Definition: game.cpp:2813
void display_faction_epilogues()
Definition: game.cpp:2830
void display_messages()
Definition: messages.cpp:827
void show_scores_ui(const achievements_tracker &achievements, stats_tracker &stats, const kill_tracker &kills)
Definition: scores_ui.cpp:69

References achievements_tracker_ptr, diary::death_entry(), disp_NPC_epilogues(), display_faction_epilogues(), Messages::display_messages(), follower_ids, gamemode, avatar::get_avatar_diary(), get_kill_tracker(), show_scores_ui(), stats(), and u.

Referenced by cleanup_at_end().

◆ despawn_monster()

void game::despawn_monster ( monster critter)

Despawn a specific monster, it's stored on the overmap.

Also removes it from the creature tracker. Keep in mind that any monster index may point to a different monster after calling this (or to no monster at all).

Definition at line 11050 of file game.cpp.

11051{
11052 if( !critter.is_hallucination() ) {
11053 // hallucinations aren't stored, they come and go as they like,
11055 }
11056
11057 critter.on_unload();
11058 remove_zombie( critter );
11059 // simulate it being dead so further processing of it (e.g. in monmove) will yield
11060 critter.set_hp( 0 );
11061}
void remove_zombie(const monster &critter)
Definition: game.cpp:4734
bool is_hallucination() const override
Definition: monster.cpp:2714
void on_unload()
Do some cleanup and caching as monster is being unloaded from map.
Definition: monster.cpp:3050
void set_hp(int hp)
Directly set the current hp of the monster (not capped at the maximal hp).
Definition: monster.cpp:1685
void despawn_monster(const monster &critter)
Despawn the monster back onto the overmap.

References overmapbuffer::despawn_monster(), monster::is_hallucination(), monster::on_unload(), overmap_buffer, remove_zombie(), and monster::set_hp().

Referenced by cleanup_at_end(), monmove(), place_player_overmap(), and shift_monsters().

◆ disable_robot()

bool game::disable_robot ( const tripoint p)

If there is a robot (that can be disabled), query the player and try to disable it.

Returns
true if the robot has been disabled or a similar action has been done. false if the player did not choose any action and the function has effectively done nothing.

Definition at line 8657 of file game.cpp.

8658{
8659 monster *const mon_ptr = critter_at<monster>( p );
8660 if( !mon_ptr ) {
8661 return false;
8662 }
8663 monster &critter = *mon_ptr;
8664 if( critter.friendly == 0 || critter.has_effect( effect_pet ) ||
8665 critter.has_flag( MF_RIDEABLE_MECH ) ||
8666 ( critter.has_flag( MF_PAY_BOT ) && critter.has_effect( effect_paid ) ) ) {
8667 // Can only disable / reprogram friendly monsters
8668 return false;
8669 }
8670 const auto mid = critter.type->id;
8671 const auto mon_item_id = critter.type->revert_to_itype;
8672 if( !mon_item_id.is_empty() &&
8673 query_yn( _( "Deactivate the %s?" ), critter.name() ) ) {
8674
8675 u.moves -= 100;
8676 m.add_item_or_charges( p, critter.to_item() );
8677 if( !critter.has_flag( MF_INTERIOR_AMMO ) ) {
8678 for( auto &ammodef : critter.ammo ) {
8679 if( ammodef.second > 0 ) {
8680 m.spawn_item( p.xy(), ammodef.first, 1, ammodef.second, calendar::turn );
8681 }
8682 }
8683 }
8684 remove_zombie( critter );
8685 return true;
8686 }
8687 // Manhacks are special, they have their own menu here.
8688 if( mid == mon_manhack ) {
8689 int choice = UILIST_CANCEL;
8690 if( critter.has_effect( effect_docile ) ) {
8691 choice = uilist( _( "Reprogram the manhack?" ), { _( "Engage targets." ) } );
8692 } else {
8693 choice = uilist( _( "Reprogram the manhack?" ), { _( "Follow me." ) } );
8694 }
8695 switch( choice ) {
8696 case 0:
8697 if( critter.has_effect( effect_docile ) ) {
8698 critter.remove_effect( effect_docile );
8699 if( one_in( 3 ) ) {
8700 add_msg( _( "The %s hovers momentarily as it surveys the area." ),
8701 critter.name() );
8702 }
8703 } else {
8704 critter.add_effect( effect_docile, 1_turns, num_bp );
8705 if( one_in( 3 ) ) {
8706 add_msg( _( "The %s lets out a whirring noise and starts to follow you." ),
8707 critter.name() );
8708 }
8709 }
8710 u.moves -= 100;
8711 return true;
8712 default:
8713 break;
8714 }
8715 }
8716 return false;
8717}
@ num_bp
Definition: bodypart.h:54
bool remove_effect(const efftype_id &eff_id, body_part bp=num_bp)
Removes a listed effect.
Definition: creature.cpp:1164
void spawn_item(const tripoint &p, const itype_id &type_id, unsigned quantity=1, int charges=0, const time_point &birthday=calendar::start_of_cataclysm, int damlevel=0)
Definition: map.cpp:4314
bool has_flag(m_flag f) const override
Definition: monster.cpp:894
item to_item() const
Convert this monster into an item (see mtype::revert_to_itype).
Definition: monster.cpp:2854
void add_effect(const efftype_id &eff_id, const time_duration &dur, const bodypart_str_id &bp, int intensity=0, bool force=false, bool deferred=false) override
Performs any monster-specific modifications to the arguments before passing to Creature::add_effect()...
Definition: monster.cpp:1861
int friendly
Definition: monster.h:471
std::string name(unsigned int quantity=1) const
Definition: monster.cpp:489
std::map< itype_id, int > ammo
Definition: monster.h:512
static const efftype_id effect_pet("pet")
static const efftype_id effect_docile("docile")
static const efftype_id effect_paid("paid")
static const mtype_id mon_manhack("mon_manhack")
@ MF_INTERIOR_AMMO
Definition: mtype.h:147
@ MF_RIDEABLE_MECH
Definition: mtype.h:116
@ MF_PAY_BOT
Definition: mtype.h:122
itype_id revert_to_itype
If this is not empty, the monster can be converted into an item of this type (if it's friendly).
Definition: mtype.h:365
constexpr point xy() const
Definition: point.h:206
const int UILIST_CANCEL
Definition: ui.h:28

References _, monster::add_effect(), map::add_item_or_charges(), add_msg(), monster::ammo, effect_docile, effect_paid, effect_pet, monster::friendly, Creature::has_effect(), monster::has_flag(), mtype::id, m, MF_INTERIOR_AMMO, MF_PAY_BOT, MF_RIDEABLE_MECH, mon_manhack, Creature::moves, monster::name(), num_bp, one_in(), query_yn(), Creature::remove_effect(), remove_zombie(), mtype::revert_to_itype, map::spawn_item(), monster::to_item(), calendar::turn, monster::type, u, UILIST_CANCEL, and tripoint::xy().

Referenced by examine().

◆ disp_NPC_epilogues()

void game::disp_NPC_epilogues ( )
private

Definition at line 2813 of file game.cpp.

2814{
2815 // TODO: This search needs to be expanded to all NPCs
2816 for( auto elem : follower_ids ) {
2818 if( !guy ) {
2819 continue;
2820 }
2821 const auto new_win = []() {
2823 point( std::max( 0, ( TERMX - FULL_SCREEN_WIDTH ) / 2 ),
2824 std::max( 0, ( TERMY - FULL_SCREEN_HEIGHT ) / 2 ) ) );
2825 };
2826 scrollable_text( new_win, guy->disp_name(), guy->get_epilogue() );
2827 }
2828}
shared_ptr_fast< npc > find_npc(character_id id)
Find the npc with the given ID.
void scrollable_text(const std::function< catacurses::window()> &init_window, const std::string &title, const std::string &text)
Definition: output.cpp:352

References overmapbuffer::find_npc(), follower_ids, FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH, catacurses::newwin(), overmap_buffer, scrollable_text(), TERMX, and TERMY.

Referenced by death_screen().

◆ disp_NPCs()

void game::disp_NPCs ( )

Definition at line 2864 of file game.cpp.

2865{
2866 const tripoint_abs_omt ppos = u.global_omt_location();
2867 const tripoint &lpos = u.pos();
2868 std::vector<shared_ptr_fast<npc>> npcs = overmap_buffer.get_npcs_near_player( 100 );
2869 std::sort( npcs.begin(), npcs.end(), npc_dist_to_player() );
2870
2872 ui_adaptor ui;
2873 ui.on_screen_resize( [&]( ui_adaptor & ui ) {
2876 TERMY > FULL_SCREEN_HEIGHT ? ( TERMY - FULL_SCREEN_HEIGHT ) / 2 : 0 ) );
2877 ui.position_from_window( w );
2878 } );
2879 ui.mark_resize();
2880 ui.on_redraw( [&]( const ui_adaptor & ) {
2881 werase( w );
2882 mvwprintz( w, point_zero, c_white, _( "Your overmap position: %s" ), ppos.to_string() );
2883 // NOLINTNEXTLINE(cata-use-named-point-constants)
2884 mvwprintz( w, point( 0, 1 ), c_white, _( "Your local position: %s" ), lpos.to_string() );
2885 size_t i;
2886 for( i = 0; i < 20 && i < npcs.size(); i++ ) {
2887 const tripoint_abs_omt apos = npcs[i]->global_omt_location();
2888 mvwprintz( w, point( 0, i + 3 ), c_white, "%s: %s", npcs[i]->name,
2889 apos.to_string() );
2890 }
2891 for( const monster &m : all_monsters() ) {
2892 mvwprintz( w, point( 0, i + 3 ), c_white, "%s: %d, %d, %d", m.name(),
2893 m.posx(), m.posy(), m.posz() );
2894 ++i;
2895 }
2896 wnoutrefresh( w );
2897 } );
2898
2899 input_context ctxt( "DISP_NPCS" );
2900 ctxt.register_action( "CONFIRM" );
2901 ctxt.register_action( "QUIT" );
2902 ctxt.register_action( "HELP_KEYBINDINGS" );
2903 bool stop = false;
2904 while( !stop ) {
2906 const std::string action = ctxt.handle_input();
2907 if( action == "CONFIRM" || action == "QUIT" ) {
2908 stop = true;
2909 }
2910 }
2911}
tripoint_abs_omt global_omt_location() const
Returns the location of the player in global overmap terrain coordinates.
Definition: character.cpp:6275
std::string to_string() const
Definition: coordinates.h:140
Represents a context in which a set of actions can be performed.
Definition: input.h:382
std::string name(const tripoint &p)
Definition: map.cpp:1390
void wnoutrefresh(const window &win)
Definition: ncurses_def.cpp:44
void werase(const window &win)
Definition: ncurses_def.cpp:54
std::string to_string() const
Definition: point.cpp:34

References _, action, all_monsters(), c_white, FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH, overmapbuffer::get_npcs_near_player(), Character::global_omt_location(), input_context::handle_input(), m, mvwprintz(), map::name(), om_direction::name(), catacurses::newwin(), overmap_buffer, point_zero, Character::pos(), ui_manager::redraw(), input_context::register_action(), TERMX, TERMY, coords::coord_point< Point, Origin, Scale >::to_string(), tripoint::to_string(), u, catacurses::werase(), and catacurses::wnoutrefresh().

◆ display_faction_epilogues()

void game::display_faction_epilogues ( )
private

Definition at line 2830 of file game.cpp.

2831{
2832 for( const auto &elem : faction_manager_ptr->all() ) {
2833 if( elem.second.known_by_u ) {
2834 const std::vector<std::string> epilogue = elem.second.epilogue();
2835 if( !epilogue.empty() ) {
2836 const auto new_win = []() {
2838 point( std::max( 0, ( TERMX - FULL_SCREEN_WIDTH ) / 2 ),
2839 std::max( 0, ( TERMY - FULL_SCREEN_HEIGHT ) / 2 ) ) );
2840 };
2841 scrollable_text( new_win, elem.second.name,
2842 std::accumulate( epilogue.begin() + 1, epilogue.end(), epilogue.front(),
2843 []( const std::string & lhs, const std::string & rhs ) -> std::string {
2844 return lhs + "\n" + rhs;
2845 } ) );
2846 }
2847 }
2848 }
2849}
pimpl< faction_manager > faction_manager_ptr
Definition: game.h:973

References faction_manager_ptr, FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH, catacurses::newwin(), scrollable_text(), TERMX, and TERMY.

Referenced by death_screen().

◆ display_lighting()

void game::display_lighting ( )
private

Definition at line 11276 of file game.cpp.

11277{
11278 if( use_tiles ) {
11280 if( !g->display_overlay_state( ACTION_DISPLAY_LIGHTING ) ) {
11281 return;
11282 }
11283 uilist lighting_menu;
11284 std::vector<std::string> lighting_menu_strings{
11285 "Global lighting conditions"
11286 };
11287
11288 int count = 0;
11289 for( const auto &menu_str : lighting_menu_strings ) {
11290 lighting_menu.addentry( count++, true, MENU_AUTOASSIGN, "%s", menu_str );
11291 }
11292
11293 lighting_menu.w_y_setup = 0;
11294 lighting_menu.query();
11295 if( ( lighting_menu.ret >= 0 ) &&
11296 ( static_cast<size_t>( lighting_menu.ret ) < lighting_menu_strings.size() ) ) {
11297 g->displaying_lighting_condition = lighting_menu.ret;
11298 }
11299 }
11300}
@ ACTION_DISPLAY_LIGHTING
Toggle lighting conditions map.
Definition: action.h:321
bool use_tiles
Use tiles for display.
void display_toggle_overlay(action_id)
Definition: game.cpp:11172
pos_scalar w_y_setup
Definition: ui.h:338
constexpr size_t count()
Definition: fmtlib_core.h:1073
const int MENU_AUTOASSIGN
Definition: ui.h:31

References ACTION_DISPLAY_LIGHTING, uilist::addentry(), detail::count(), display_toggle_overlay(), g, MENU_AUTOASSIGN, uilist::query(), uilist::ret, use_tiles, and uilist::w_y_setup.

Referenced by handle_action(), and look_around().

◆ display_overlay_state()

bool game::display_overlay_state ( action_id  action)

Definition at line 11167 of file game.cpp.

11168{
11170}
std::optional< action_id > displaying_overlays
Definition: game.h:917

References action, and displaying_overlays.

Referenced by display_toggle_overlay(), and display_visibility().

◆ display_radiation()

void game::display_radiation ( )
private

Definition at line 11302 of file game.cpp.

11303{
11304 if( use_tiles ) {
11306 }
11307}
@ ACTION_DISPLAY_RADIATION
Toggle radiation map.
Definition: action.h:323

References ACTION_DISPLAY_RADIATION, display_toggle_overlay(), and use_tiles.

Referenced by handle_action(), and look_around().

◆ display_scent()

void game::display_scent ( )
private

Definition at line 11181 of file game.cpp.

11182{
11183 if( use_tiles ) {
11185 } else {
11186 int div;
11187 bool got_value = query_int( div, _( "Set the Scent Map sensitivity to (0 to cancel)?" ) );
11188 if( !got_value || div < 1 ) {
11189 add_msg( _( "Never mind." ) );
11190 return;
11191 }
11192 shared_ptr_fast<game::draw_callback_t> scent_cb = make_shared_fast<game::draw_callback_t>( [&]() {
11193 scent.draw( w_terrain, div * 2, u.pos() + u.view_offset );
11194 } );
11195 g->add_draw_callback( scent_cb );
11196
11199 }
11200}
@ ACTION_DISPLAY_SCENT
Toggle scent map.
Definition: action.h:283
void wait_for_any_key()
Wait until the user presses a key.
Definition: input.cpp:1303
tripoint view_offset
Definition: player.h:233
void draw(const catacurses::window &win, int div, const tripoint &center) const
Definition: scent_map.cpp:70
input_manager inp_mngr
Definition: input.cpp:109
bool query_int(int &result, int default_val, const std::string &text)
Definition: output.cpp:718

References _, ACTION_DISPLAY_SCENT, add_msg(), display_toggle_overlay(), scent_map::draw(), g, inp_mngr, Character::pos(), query_int(), ui_manager::redraw(), scent, u, use_tiles, player::view_offset, w_terrain, and input_manager::wait_for_any_key().

Referenced by handle_action(), and look_around().

◆ display_temperature()

void game::display_temperature ( )
private

Definition at line 11202 of file game.cpp.

11203{
11204 if( use_tiles ) {
11206 }
11207}
@ ACTION_DISPLAY_TEMPERATURE
Toggle temperature map.
Definition: action.h:315

References ACTION_DISPLAY_TEMPERATURE, display_toggle_overlay(), and use_tiles.

Referenced by handle_action(), and look_around().

◆ display_toggle_overlay()

void game::display_toggle_overlay ( action_id  action)

Definition at line 11172 of file game.cpp.

11173{
11174 if( display_overlay_state( action ) ) {
11175 displaying_overlays.reset();
11176 } else {
11178 }
11179}
bool display_overlay_state(action_id)
Definition: game.cpp:11167

References action, display_overlay_state(), and displaying_overlays.

Referenced by display_lighting(), display_radiation(), display_scent(), display_temperature(), display_transparency(), display_vehicle_ai(), and display_visibility().

◆ display_transparency()

void game::display_transparency ( )
private

Definition at line 11309 of file game.cpp.

11310{
11311 if( use_tiles ) {
11313 }
11314}
@ ACTION_DISPLAY_TRANSPARENCY
Toggle transparency map.
Definition: action.h:325

References ACTION_DISPLAY_TRANSPARENCY, display_toggle_overlay(), and use_tiles.

Referenced by handle_action(), and look_around().

◆ display_vehicle_ai()

void game::display_vehicle_ai ( )
private

Definition at line 11209 of file game.cpp.

11210{
11211 if( use_tiles ) {
11213 }
11214}
@ ACTION_DISPLAY_VEHICLE_AI
Toggle vehicle autopilot data.
Definition: action.h:317

References ACTION_DISPLAY_VEHICLE_AI, display_toggle_overlay(), and use_tiles.

Referenced by handle_action().

◆ display_visibility()

void game::display_visibility ( )
private

Definition at line 11216 of file game.cpp.

11217{
11218 if( use_tiles ) {
11221 std::vector< tripoint > locations;
11222 uilist creature_menu;
11223 int num_creatures = 0;
11224 creature_menu.addentry( num_creatures++, true, MENU_AUTOASSIGN, "%s", _( "You" ) );
11225 locations.emplace_back( g->u.pos() ); // add player first.
11226 for( const Creature &critter : g->all_creatures() ) {
11227 if( critter.is_player() ) {
11228 continue;
11229 }
11230 creature_menu.addentry( num_creatures++, true, MENU_AUTOASSIGN, critter.disp_name() );
11231 locations.emplace_back( critter.pos() );
11232 }
11233
11234 pointmenu_cb callback( locations );
11235 creature_menu.callback = &callback;
11236 creature_menu.w_y_setup = 0;
11237 creature_menu.query();
11238 if( creature_menu.ret >= 0 && static_cast<size_t>( creature_menu.ret ) < locations.size() ) {
11239 Creature *creature = critter_at<Creature>( locations[creature_menu.ret] );
11241 }
11242 } else {
11244 }
11245 }
11246}
@ ACTION_DISPLAY_VISIBILITY
Toggle visibility map.
Definition: action.h:319
size_t num_creatures() const
Returns the approximate number of creatures in the reality bubble.
Definition: game.cpp:4724
Creature * displaying_visibility_creature
Creature for which to display the visibility map.
Definition: game.h:1009
Callback for uilist that pairs menu entries with points When an entry is selected,...
Definition: ui.h:423
uilist_callback * callback
Definition: ui.h:335
generic_factory< overmap_location > locations("overmap location")

References _, ACTION_DISPLAY_VISIBILITY, uilist::addentry(), uilist::callback, creature, display_overlay_state(), display_toggle_overlay(), displaying_visibility_creature, g, anonymous_namespace{overmap_location.cpp}::locations, MENU_AUTOASSIGN, num_creatures(), uilist::query(), uilist::ret, use_tiles, and uilist::w_y_setup.

Referenced by handle_action().

◆ do_turn()

bool game::do_turn ( )

MAIN GAME LOOP.

Returns true if game is over (death, saved, quit, etc.).

Definition at line 1349 of file game.cpp.

1350{
1351 if( is_game_over() ) {
1352 return cleanup_at_end();
1353 }
1354 // Actual stuff
1355 if( new_game ) {
1356 new_game = false;
1357 } else {
1358 gamemode->per_turn();
1359 calendar::turn += 1_turns;
1360 }
1361
1362 // starting a new turn, clear out temperature cache
1364 weather.clear_temp_cache();
1365
1366 if( npcs_dirty ) {
1367 load_npcs();
1368 }
1369
1372 // If controlling a vehicle that is owned by someone else
1374 vehicle *veh = veh_pointer_or_null( m.veh_at( u.pos() ) );
1375 if( veh && !veh->handle_potential_theft( u, true ) ) {
1376 veh->handle_potential_theft( u, false, false );
1377 }
1378 }
1379 // If riding a horse - chance to spook
1380 if( u.is_mounted() ) {
1382 }
1383 if( calendar::once_every( 1_days ) ) {
1385 }
1386
1387 // Move hordes every 2.5 min
1390 // Hordes that reached the reality bubble need to spawn,
1391 // make them spawn in invisible areas only.
1392 m.spawn_monsters( false );
1393 }
1394
1396
1397 u.update_body();
1398
1399 // Auto-save if autosave is enabled
1400 if( get_option<bool>( "AUTOSAVE" ) &&
1401 calendar::once_every( 1_turns * get_option<int>( "AUTOSAVE_TURNS" ) ) &&
1402 !u.is_dead_state() ) {
1403 autosave();
1404 }
1405
1406 weather.update_weather();
1408
1412 // Process NPC sound events before they move or they hear themselves talking
1413 for( npc &guy : all_npcs() ) {
1414 if( rl_dist( guy.pos(), u.pos() ) < MAX_VIEW_DISTANCE ) {
1416 }
1417 }
1418
1419 // Process sound events into sound markers for display to the player.
1421
1422 if( u.is_deaf() ) {
1424 }
1425
1426 if( !u.has_effect( effect_sleep ) || uquit == QUIT_WATCH ) {
1427 if( u.moves > 0 || uquit == QUIT_WATCH ) {
1428 while( u.moves > 0 || uquit == QUIT_WATCH ) {
1429 cleanup_dead();
1431 // Process any new sounds the player caused during their turn.
1432 for( npc &guy : all_npcs() ) {
1433 if( rl_dist( guy.pos(), u.pos() ) < MAX_VIEW_DISTANCE ) {
1435 }
1436 }
1439 wait_popup.reset();
1441 }
1442
1443 if( queue_screenshot ) {
1447 queue_screenshot = false;
1448 }
1449
1450 if( handle_action() ) {
1452 u.action_taken();
1453 }
1454
1455 if( is_game_over() ) {
1456 return cleanup_at_end();
1457 }
1458
1459 if( uquit == QUIT_WATCH ) {
1460 break;
1461 }
1462 if( u.activity ) {
1464 }
1465 }
1466 // Reset displayed sound markers now that the turn is over.
1467 // We only want this to happen if the player had a chance to examine the sounds.
1469 }
1470 }
1471
1472 if( driving_view_offset.x != 0 || driving_view_offset.y != 0 ) {
1473 // Still have a view offset, but might not be driving anymore,
1474 // or the option has been deactivated,
1475 // might also happen when someone dives from a moving car.
1476 // or when using the handbrake.
1477 vehicle *veh = veh_pointer_or_null( m.veh_at( u.pos() ) );
1478 calc_driving_offset( veh );
1479 }
1480
1481 // No-scent debug mutation has to be processed here or else it takes time to start working
1482 if( !u.has_active_bionic( bionic_id( "bio_scent_mask" ) ) &&
1483 !u.has_trait( trait_id( "DEBUG_NOSCENT" ) ) ) {
1486 }
1487 scent.update( u.pos(), m );
1488
1489 // We need floor cache before checking falling 'n stuff
1491
1494 m.vehmove();
1495 m.process_fields();
1496 m.process_items();
1499
1500 // Apply sounds from previous turn to monster and NPC AI.
1502 // Update vision caches for monsters. If this turns out to be expensive,
1503 // consider a stripped down cache just for monsters.
1504 m.build_map_cache( get_levz(), true );
1505 monmove();
1506 if( calendar::once_every( 5_minutes ) ) {
1508 }
1509 if( calendar::once_every( 10_seconds ) ) {
1510 for( const tripoint &elem : m.get_furn_field_locations() ) {
1511 const auto &furn = m.furn( elem ).obj();
1512 for( const emit_id &e : furn.emissions ) {
1513 m.emit_field( elem, e );
1514 }
1515 }
1516 }
1519 u.process_turn();
1520
1522
1524 cleanup_dead();
1525
1526 if( u.moves < 0 && get_option<bool>( "FORCE_REDRAW" ) ) {
1529 }
1530
1531 if( get_levz() >= 0 && !u.is_underwater() ) {
1532 handle_weather_effects( weather.weather_id );
1533 }
1534
1535 const bool player_is_sleeping = u.has_effect( effect_sleep );
1536 bool wait_redraw = false;
1537 std::string wait_message;
1538 time_duration wait_refresh_rate;
1539 if( player_is_sleeping ) {
1540 wait_redraw = true;
1541 wait_message = _( "Wait till you wake up…" );
1542 wait_refresh_rate = 30_minutes;
1543 if( calendar::once_every( 1_hours ) ) {
1545 }
1546 } else if( u.has_destination() ) {
1547 wait_redraw = true;
1548 wait_message = _( "Travelling…" );
1549 wait_refresh_rate = 15_turns;
1550 } else if( const std::optional<std::string> progress = u.activity.get_progress_message( u ) ) {
1551 wait_redraw = true;
1552 wait_message = *progress;
1553 if( u.activity.id() == ACT_AUTODRIVE ) {
1554 wait_refresh_rate = 1_turns;
1555 } else {
1556 wait_refresh_rate = 5_minutes;
1557 }
1558 }
1559 if( wait_redraw ) {
1561 calendar::once_every( std::min( 1_minutes, wait_refresh_rate ) ) ) {
1562 if( first_redraw_since_waiting_started || calendar::once_every( wait_refresh_rate ) ) {
1564 }
1565
1566 // Avoid redrawing the main UI every time due to invalidation
1568 wait_popup = std::make_unique<static_popup>();
1569 wait_popup->on_top( true ).wait_message( "%s", wait_message );
1573 }
1574 } else {
1575 // Nothing to wait for now
1576 wait_popup.reset();
1578 }
1579
1582 u.apply_wetness_morale( weather.temperature );
1583
1584 if( !u.is_deaf() ) {
1586 }
1591
1592 // reset player noise
1593 u.volume = 0;
1594
1595 return false;
1596}
void action_taken()
Called after every action, invalidates player caches.
Definition: character.cpp:812
bool check_mount_is_spooked()
Definition: character.cpp:1041
void process_turn() override
Handles end-of-turn processing.
void update_bodytemp(const map &m, const weather_manager &weather)
Maintains body temperature.
Definition: character.cpp:5226
bool is_mounted() const
Definition: character.cpp:1082
bool has_destination() const
scenttype_id get_type_of_scent() const
Definition: character.cpp:8766
bool is_dead_state() const override
Returns true if the character should be dead.
Definition: character.cpp:499
bool is_deaf() const
Definition: character.cpp:4511
void update_body()
Updates all "biology" by one turn.
Definition: character.cpp:4703
bool has_active_bionic(const bionic_id &b) const
Returns true if the player has the entered bionic id and it is powered on.
Definition: character.cpp:1825
void apply_wetness_morale(int temperature)
Recalculates morale penalty/bonus from wetness based on mutations, equipment and temperature.
Definition: suffer.cpp:1759
virtual bool is_underwater() const
Definition: creature.cpp:172
static DynamicDataLoader & get_instance()
Returns the single instance of this class.
Definition: init.cpp:120
int get_levz() const
Definition: game.cpp:11936
void overmap_npc_move()
Definition: game.cpp:4204
class game::debug_hour_timer debug_hour_timer
npc_range all_npcs()
Same as all_creatures but iterators only over npcs.
Definition: game.cpp:12046
void monmove()
Definition: game.cpp:4078
void autopilot_vehicles()
process vehicles that are following the player
Definition: game.cpp:1661
void add_artifact_dreams()
Definition: game.cpp:11878
int moves_since_last_save
Definition: game.h:1039
bool take_screenshot() const
Saves a screenshot of the current viewport, as a PNG file.
Definition: game.cpp:7175
void calc_driving_offset(vehicle *veh=nullptr)
Definition: game.cpp:1247
bool cleanup_at_end()
Definition: game.cpp:943
std::unique_ptr< static_popup > wait_popup
Definition: game.h:1075
bool queue_screenshot
Definition: game.h:1018
friend weather_manager & get_weather()
Definition: weather.cpp:64
void autosave()
Definition: game.cpp:11367
void process_activity()
Definition: game.cpp:1650
void update_stair_monsters()
Definition: game.cpp:10841
void process_voluntary_act_interrupt()
Definition: game.cpp:1610
void load_npcs()
Makes any nearby NPCs on the overmap active.
Definition: game.cpp:817
bool npcs_dirty
Has a NPC been spawned since last load?
Definition: game.h:1046
void cleanup_dead()
Definition: game.cpp:4043
bool is_game_over()
Definition: game.cpp:2367
void perhaps_add_random_npc()
Definition: game.cpp:11099
void mon_info_update()
Definition: game.cpp:3842
bool handle_action()
const T & obj() const
Definition: ammo_effect.cpp:26
void build_floor_caches()
Definition: map.cpp:8196
void process_falling()
Invoked drop_everything on cached dirty tiles.
Definition: map.cpp:2356
void emit_field(const tripoint &pos, const emit_id &src, float mul=1.0f)
Runs one cycle of emission src which may result in propagation of fields.
Definition: map_field.cpp:1928
const std::vector< tripoint > & get_furn_field_locations() const
Definition: map.cpp:7888
void spawn_monsters(bool ignore_sight)
Spawn monsters from submap spawn points and from the overmap.
Definition: map.cpp:7847
void vehmove()
Definition: map.cpp:474
void creature_in_field(Creature &critter)
Apply field effects to the creature when it's on a square with fields.
Definition: map_field.cpp:1563
void process_fields()
Definition: map_field.cpp:142
furn_id furn(const tripoint &p) const
Definition: map.cpp:1413
void build_map_cache(int zlev, bool skip_lightmap=false)
Definition: map.cpp:8362
void process_items()
Definition: map.cpp:4700
static void process_all()
Handles mission deadline processing.
Definition: mission.cpp:98
void set_scent(const tripoint_abs_omt &loc, int strength)
Method to set a scent trace.
void process_mongroups()
Process nearby monstergroups (dying mostly).
void move_hordes()
Let hordes move a step.
const activity_id & id() const
std::optional< std::string > get_progress_message(const avatar &u) const
Helper that returns an activity specific progress message.
int volume
Definition: player.h:236
int scent
Definition: player.h:245
void set(const tripoint &p, int value, const scenttype_id &type=scenttype_id())
Get the scent value at the given position.
Definition: scent_map.cpp:102
void update(const tripoint &center, map &m)
Definition: scent_map.cpp:150
static constexpr time_duration from_minutes(const T m)
Definition: calendar.h:212
void process()
Process all queued events, potentially altering the game state and modifying the event queue.
static const activity_id ACT_AUTODRIVE("ACT_AUTODRIVE")
static const efftype_id effect_sleep("sleep")
@ QUIT_WATCH
Definition: game.h:73
static constexpr int MAX_VIEW_DISTANCE
void handle_weather_effects(const weather_type_id &w)
Definition: weather.cpp:525
bool once_every(const time_duration &event_frequency)
Predicate to handle rate-limiting.
Definition: calendar.cpp:490
void run_on_every_x_hooks(lua_state &)
Definition: catalua.cpp:92
void update_body_wetness(Character &who, const w_point &weather)
Maintains body wetness and handles the rate at which the player dries.
explosion_queue & get_explosion_queue()
Definition: explosion.cpp:1921
void do_vehicle_engine_sfx()
Definition: sounds.cpp:1613
void do_hearing_loss(int turns=-1)
Definition: sounds.cpp:1608
void do_danger_music()
Definition: sounds.cpp:1612
void do_vehicle_exterior_engine_sfx()
Definition: sounds.cpp:1614
void do_fatigue()
Definition: sounds.cpp:1633
void remove_hearing_loss()
Definition: sounds.cpp:1609
void process_sound_markers(player *p)
Definition: sounds.cpp:387
void process_sounds()
Definition: sounds.cpp:305
void reset_markers()
Definition: sounds.cpp:573
vehicle * veh_pointer_or_null(const optional_vpart_position &p)

References _, ACT_AUTODRIVE, Character::action_taken(), Character::activity, add_artifact_dreams(), all_npcs(), Character::apply_wetness_morale(), autopilot_vehicles(), autosave(), map::build_floor_caches(), map::build_map_cache(), calc_driving_offset(), Character::check_mount_is_spooked(), cleanup_at_end(), cleanup_dead(), Character::controlling_vehicle, map::creature_in_field(), sfx::do_danger_music(), sfx::do_fatigue(), sfx::do_hearing_loss(), sfx::do_vehicle_engine_sfx(), sfx::do_vehicle_exterior_engine_sfx(), driving_view_offset, effect_sleep, map::emit_field(), explosion_handler::explosion_queue::execute(), first_redraw_since_waiting_started, time_duration::from_minutes(), map::furn(), gamemode, explosion_handler::get_explosion_queue(), map::get_furn_field_locations(), DynamicDataLoader::get_instance(), get_levz(), player_activity::get_progress_message(), Character::get_type_of_scent(), get_weather, Character::global_omt_location(), grid_tracker_ptr, handle_action(), vehicle::handle_potential_theft(), handle_weather_effects(), Character::has_active_bionic(), Character::has_destination(), Character::has_distant_destination(), Creature::has_effect(), Character::has_trait(), player_activity::id(), Character::in_vehicle, invalidate_main_ui_adaptor(), Character::is_dead_state(), Character::is_deaf(), is_game_over(), Character::is_mounted(), Creature::is_underwater(), load_npcs(), m, MAX_VIEW_DISTANCE, mon_info_update(), monmove(), overmapbuffer::move_hordes(), Creature::moves, moves_since_last_save, new_game, npcs_dirty, int_id< T >::obj(), calendar::once_every(), overmap_buffer, overmap_npc_move(), perhaps_add_random_npc(), Character::pos(), game::debug_hour_timer::print_time(), timed_event_manager::process(), process_activity(), mission::process_all(), map::process_falling(), map::process_fields(), map::process_items(), overmapbuffer::process_mongroups(), sounds::process_sound_markers(), sounds::process_sounds(), Character::process_turn(), process_voluntary_act_interrupt(), queue_screenshot, QUIT_WATCH, ui_manager::redraw(), refresh_display(), sfx::remove_hearing_loss(), reset_light_level(), sounds::reset_markers(), rl_dist(), cata::run_on_every_x_hooks(), scent, player::scent, scent_map::set(), overmapbuffer::set_scent(), map::spawn_monsters(), take_screenshot(), timed_events, calendar::turn, u, scent_map::update(), Character::update_body(), character_funcs::update_body_wetness(), Character::update_bodytemp(), update_stair_monsters(), uquit, map::veh_at(), veh_pointer_or_null(), map::vehmove(), player::volume, wait_popup, point::x, and point::y.

◆ draw()

void game::draw ( )

Definition at line 3101 of file game.cpp.

3102{
3103 if( test_mode ) {
3104 return;
3105 }
3106
3107 //temporary fix for updating visibility for minimap
3108 ter_view_p.z = ( u.pos() + u.view_offset ).z;
3111
3112 werase( w_terrain );
3113 draw_ter();
3114 for( auto it = draw_callbacks.begin(); it != draw_callbacks.end(); ) {
3115 shared_ptr_fast<draw_callback_t> cb = it->lock();
3116 if( cb ) {
3117 ( *cb )();
3118 ++it;
3119 } else {
3120 it = draw_callbacks.erase( it );
3121 }
3122 }
3124
3125 draw_panels( true );
3126}
bool test_mode
Set to true when running in test mode (e.g.
tripoint ter_view_p
Definition: game.h:985
void draw_panels(bool force_draw=false)
Definition: game.cpp:3128
void draw_ter(bool draw_sounds=true)
Definition: game.cpp:3242
void update_visibility_cache(int zlev)
Definition: map.cpp:5736
int z
Definition: point.h:138

References map::build_map_cache(), draw_callbacks, draw_panels(), draw_ter(), m, Character::pos(), ter_view_p, test_mode, u, map::update_visibility_cache(), player::view_offset, w_terrain, catacurses::werase(), catacurses::wnoutrefresh(), and tripoint::z.

◆ draw_below_override()

void game::draw_below_override ( const tripoint p,
bool  draw 
)

Definition at line 1023 of file animation.cpp.

1024{
1025}

◆ draw_bullet()

void game::draw_bullet ( const tripoint t,
int  i,
const std::vector< tripoint > &  trajectory,
char  bullet 
)

Definition at line 578 of file animation.cpp.

580{
581 draw_bullet_curses( m, t, bullet, &trajectory[i] );
582}
void draw_bullet_curses(map &m, const tripoint &t, const char bullet, const tripoint *const p)
Definition: animation.cpp:460
std::vector< tripoint > trajectory
Definition: ranged.h:37

References anonymous_namespace{animation.cpp}::draw_bullet_curses(), and m.

◆ draw_critter()

void game::draw_critter ( const Creature critter,
const tripoint center 
)

Definition at line 3224 of file game.cpp.

3225{
3226 draw_critter_internal( w_terrain, critter, center, false, m, u );
3227}
static void draw_critter_internal(const catacurses::window &w, const Creature &critter, const tripoint &center, bool inverted, const map &m, const avatar &u)
Definition: game.cpp:3191

References center, draw_critter_internal(), m, u, and w_terrain.

Referenced by draw_ter().

◆ draw_critter_highlighted()

void game::draw_critter_highlighted ( const Creature critter,
const tripoint center 
)

Definition at line 3229 of file game.cpp.

3230{
3231 draw_critter_internal( w_terrain, critter, center, true, m, u );
3232}

References center, draw_critter_internal(), m, u, and w_terrain.

◆ draw_cursor()

void game::draw_cursor ( const tripoint p)

Definition at line 784 of file animation.cpp.

785{
786 const tripoint rp = relative_view_pos( *this, p );
787 mvwputch_inv( w_terrain, rp.xy(), c_light_green, 'X' );
788}
#define c_light_green
Definition: color.h:28
tripoint relative_view_pos(const game &g, const tripoint &p) noexcept
Definition: animation.cpp:128
void mvwputch_inv(const catacurses::window &w, point p, nc_color FG, int ch)
Definition: output.cpp:491

References c_light_green, mvwputch_inv(), anonymous_namespace{animation.cpp}::relative_view_pos(), w_terrain, and tripoint::xy().

Referenced by draw_look_around_cursor().

◆ draw_field_override()

void game::draw_field_override ( const tripoint p,
const field_type_id id 
)

Definition at line 979 of file animation.cpp.

980{
981}

◆ draw_furniture_override()

void game::draw_furniture_override ( const tripoint p,
const furn_id id 
)

Definition at line 940 of file animation.cpp.

941{
942}

◆ draw_graffiti_override()

void game::draw_graffiti_override ( const tripoint p,
bool  has 
)

Definition at line 953 of file animation.cpp.

954{
955}

◆ draw_highlight()

void game::draw_highlight ( const tripoint p)

Definition at line 797 of file animation.cpp.

798{
799 // Do nothing
800}

◆ draw_hit_mon()

void game::draw_hit_mon ( const tripoint p,
const monster m,
bool  dead = false 
)

Definition at line 641 of file animation.cpp.

642{
643 draw_hit_mon_curses( p, m, u, dead );
644}
void draw_hit_mon_curses(const tripoint &center, const monster &m, const player &u, const bool dead)
Definition: animation.cpp:612

References dead, anonymous_namespace{animation.cpp}::draw_hit_mon_curses(), m, and u.

◆ draw_hit_player()

void game::draw_hit_player ( const Character p,
int  dam 
)

Definition at line 686 of file animation.cpp.

687{
688 draw_hit_player_curses( *this, p, dam );
689}
void draw_hit_player_curses(const game &g, const Character &p, const int dam)
Definition: animation.cpp:649

References anonymous_namespace{animation.cpp}::draw_hit_player_curses().

◆ draw_item_override()

void game::draw_item_override ( const tripoint p,
const itype_id id,
const mtype_id mid,
bool  hilite 
)

Definition at line 993 of file animation.cpp.

995{
996}

◆ draw_line() [1/2]

void game::draw_line ( const tripoint p,
const std::vector< tripoint > &  points 
)

Definition at line 770 of file animation.cpp.

771{
772 draw_line_curses( *this, points );
773}
void draw_line_curses(game &g, const std::vector< tripoint > &points)
Definition: animation.cpp:750

References anonymous_namespace{animation.cpp}::draw_line_curses().

◆ draw_line() [2/2]

void game::draw_line ( const tripoint p,
const tripoint center_point,
const std::vector< tripoint > &  points,
bool  noreveal = false 
)

Definition at line 737 of file animation.cpp.

739{
740 if( !u.sees( p ) ) {
741 return;
742 }
743
744 draw_line_curses( *this, center, points, noreveal );
745}

References center, anonymous_namespace{animation.cpp}::draw_line_curses(), Character::sees(), and u.

Referenced by draw_ter().

◆ draw_look_around_cursor()

void game::draw_look_around_cursor ( const tripoint lp,
const visibility_variables cache 
)

Definition at line 5707 of file game.cpp.

5708{
5709 if( !liveview.is_enabled() ) {
5710#if defined( TILES )
5711 if( is_draw_tiles_mode() ) {
5712 draw_cursor( lp );
5713 return;
5714 }
5715#endif
5716 const tripoint view_center = u.pos() + u.view_offset;
5717 visibility_type visibility = VIS_HIDDEN;
5718 const bool inbounds = m.inbounds( lp );
5719 if( inbounds ) {
5720 visibility = m.get_visibility( m.apparent_light_at( lp, cache ), cache );
5721 }
5722 if( visibility == VIS_CLEAR ) {
5723 const Creature *const creature = critter_at( lp, true );
5724 if( creature != nullptr && u.sees( *creature ) ) {
5725 creature->draw( w_terrain, view_center, true );
5726 } else {
5727 m.drawsq( w_terrain, lp, drawsq_params().highlight( true ).center( view_center ) );
5728 }
5729 } else {
5730 std::string visibility_indicator;
5731 nc_color visibility_indicator_color = c_white;
5732 switch( visibility ) {
5733 case VIS_CLEAR:
5734 // Already handled by the outer if statement
5735 break;
5736 case VIS_BOOMER:
5737 case VIS_BOOMER_DARK:
5738 visibility_indicator = '#';
5739 visibility_indicator_color = c_pink;
5740 break;
5741 case VIS_DARK:
5742 visibility_indicator = '#';
5743 visibility_indicator_color = c_dark_gray;
5744 break;
5745 case VIS_LIT:
5746 visibility_indicator = '#';
5747 visibility_indicator_color = c_light_gray;
5748 break;
5749 case VIS_HIDDEN:
5750 visibility_indicator = 'x';
5751 visibility_indicator_color = c_white;
5752 break;
5753 }
5754
5755 const tripoint screen_pos = point( POSX, POSY ) + lp - view_center;
5756 mvwputch( w_terrain, screen_pos.xy(), visibility_indicator_color, visibility_indicator );
5757 }
5758 }
5759}
void draw_cursor(const tripoint &p)
Definition: animation.cpp:784
T * critter_at(const tripoint &p, bool allow_hallucination=false)
Returns the Creature at the given location.
Definition: game.cpp:4544
bool is_enabled()
Definition: live_view.cpp:75
virtual bool inbounds(const tripoint &p) const
Definition: map.cpp:7903
visibility_type get_visibility(lit_level ll, const visibility_variables &cache) const
Definition: map.cpp:5790
lit_level apparent_light_at(const tripoint &p, const visibility_variables &cache) const
Determine the visible light level for a tile, based on light_at for the tile, vision distance,...
Definition: lightmap.cpp:765
void drawsq(const catacurses::window &w, const tripoint &p, const drawsq_params &params) const
Draw the map tile at the given coordinate.
Definition: map.cpp:5968
#define c_dark_gray
Definition: color.h:20
#define c_pink
Definition: color.h:31
visibility_type
Definition: enums.h:57
@ VIS_CLEAR
Definition: enums.h:59
@ VIS_BOOMER
Definition: enums.h:61
@ VIS_DARK
Definition: enums.h:62
@ VIS_BOOMER_DARK
Definition: enums.h:63
@ VIS_HIDDEN
Definition: enums.h:58
@ VIS_LIT
Definition: enums.h:60
bool is_draw_tiles_mode()
Check whether we're in tile drawing mode.
Definition: output.cpp:2075
Draw parameters used by map::drawsq() and similar methods.
Definition: map.h:180

References map::apparent_light_at(), c_dark_gray, c_light_gray, c_pink, c_white, center, creature, critter_at(), draw_cursor(), map::drawsq(), map::get_visibility(), map::inbounds(), is_draw_tiles_mode(), live_view::is_enabled(), liveview, m, mvwputch(), Character::pos(), POSX, POSY, Character::sees(), u, player::view_offset, VIS_BOOMER, VIS_BOOMER_DARK, VIS_CLEAR, VIS_DARK, VIS_HIDDEN, VIS_LIT, w_terrain, and tripoint::xy().

Referenced by look_around().

◆ draw_minimap()

void game::draw_minimap ( )
private

Definition at line 3302 of file game.cpp.

3303{
3304
3305 // Draw the box
3306 werase( w_minimap );
3308
3309 const tripoint_abs_omt curs = u.global_omt_location();
3310 const point_abs_omt curs2( curs.xy() );
3312 bool drew_mission = targ == overmap::invalid_tripoint;
3313
3314 for( int i = -2; i <= 2; i++ ) {
3315 for( int j = -2; j <= 2; j++ ) {
3316 const point_abs_omt om( curs2 + point( i, j ) );
3317 nc_color ter_color;
3318 tripoint_abs_omt omp( om, get_levz() );
3319 std::string ter_sym;
3320 const bool seen = overmap_buffer.seen( omp );
3321 const bool vehicle_here = overmap_buffer.has_vehicle( omp );
3322 if( overmap_buffer.has_note( omp ) ) {
3323
3324 const std::string &note_text = overmap_buffer.note( omp );
3325
3326 ter_color = c_yellow;
3327 ter_sym = "N";
3328
3329 int symbolIndex = note_text.find( ':' );
3330 int colorIndex = note_text.find( ';' );
3331
3332 bool symbolFirst = symbolIndex < colorIndex;
3333
3334 if( colorIndex > -1 && symbolIndex > -1 ) {
3335 if( symbolFirst ) {
3336 if( colorIndex > 4 ) {
3337 colorIndex = -1;
3338 }
3339 if( symbolIndex > 1 ) {
3340 symbolIndex = -1;
3341 colorIndex = -1;
3342 }
3343 } else {
3344 if( symbolIndex > 4 ) {
3345 symbolIndex = -1;
3346 }
3347 if( colorIndex > 2 ) {
3348 colorIndex = -1;
3349 }
3350 }
3351 } else if( colorIndex > 2 ) {
3352 colorIndex = -1;
3353 } else if( symbolIndex > 1 ) {
3354 symbolIndex = -1;
3355 }
3356
3357 if( symbolIndex > -1 ) {
3358 int symbolStart = 0;
3359 if( colorIndex > -1 && !symbolFirst ) {
3360 symbolStart = colorIndex + 1;
3361 }
3362 ter_sym = note_text.substr( symbolStart, symbolIndex - symbolStart ).c_str()[0];
3363 }
3364
3365 if( colorIndex > -1 ) {
3366
3367 int colorStart = 0;
3368
3369 if( symbolIndex > -1 && symbolFirst ) {
3370 colorStart = symbolIndex + 1;
3371 }
3372
3373 std::string sym = note_text.substr( colorStart, colorIndex - colorStart );
3374
3375 if( sym.length() == 2 ) {
3376 if( sym == "br" ) {
3377 ter_color = c_brown;
3378 } else if( sym == "lg" ) {
3379 ter_color = c_light_gray;
3380 } else if( sym == "dg" ) {
3381 ter_color = c_dark_gray;
3382 }
3383 } else {
3384 char colorID = sym.c_str()[0];
3385 if( colorID == 'r' ) {
3386 ter_color = c_light_red;
3387 } else if( colorID == 'R' ) {
3388 ter_color = c_red;
3389 } else if( colorID == 'g' ) {
3390 ter_color = c_light_green;
3391 } else if( colorID == 'G' ) {
3392 ter_color = c_green;
3393 } else if( colorID == 'b' ) {
3394 ter_color = c_light_blue;
3395 } else if( colorID == 'B' ) {
3396 ter_color = c_blue;
3397 } else if( colorID == 'W' ) {
3398 ter_color = c_white;
3399 } else if( colorID == 'C' ) {
3400 ter_color = c_cyan;
3401 } else if( colorID == 'c' ) {
3402 ter_color = c_light_cyan;
3403 } else if( colorID == 'P' ) {
3404 ter_color = c_pink;
3405 } else if( colorID == 'm' ) {
3406 ter_color = c_magenta;
3407 }
3408 }
3409 }
3410 } else if( !seen ) {
3411 ter_sym = " ";
3412 ter_color = c_black;
3413 } else if( vehicle_here ) {
3414 ter_color = c_cyan;
3415 ter_sym = "c";
3416 } else {
3417 const oter_id &cur_ter = overmap_buffer.ter( omp );
3418 ter_sym = cur_ter->get_symbol();
3419 if( overmap_buffer.is_explored( omp ) ) {
3420 ter_color = c_dark_gray;
3421 } else {
3422 ter_color = cur_ter->get_color();
3423 }
3424 }
3425 if( !drew_mission && targ.xy() == omp.xy() ) {
3426 // If there is a mission target, and it's not on the same
3427 // overmap terrain as the player character, mark it.
3428 // TODO: Inform player if the mission is above or below
3429 drew_mission = true;
3430 if( i != 0 || j != 0 ) {
3431 ter_color = red_background( ter_color );
3432 }
3433 }
3434 if( i == 0 && j == 0 ) {
3435 mvwputch_hi( w_minimap, point( 3, 3 ), ter_color, ter_sym );
3436 } else {
3437 mvwputch( w_minimap, point( 3 + i, 3 + j ), ter_color, ter_sym );
3438 }
3439 }
3440 }
3441
3442 // Print arrow to mission if we have one!
3443 if( !drew_mission ) {
3444 double slope = curs2.x() != targ.x() ?
3445 static_cast<double>( targ.y() - curs2.y() ) / ( targ.x() - curs2.x() ) : 4;
3446
3447 if( curs2.x() == targ.x() || std::fabs( slope ) > 3.5 ) { // Vertical slope
3448 if( targ.y() > curs2.y() ) {
3449 mvwputch( w_minimap, point( 3, 6 ), c_red, "*" );
3450 } else {
3451 mvwputch( w_minimap, point( 3, 0 ), c_red, "*" );
3452 }
3453 } else {
3454 int arrowx = -1;
3455 int arrowy = -1;
3456 if( std::fabs( slope ) >= 1. ) { // y diff is bigger!
3457 arrowy = targ.y() > curs2.y() ? 6 : 0;
3458 arrowx =
3459 static_cast<int>( 3 + 3 * ( targ.y() > curs2.y() ? slope : ( 0 - slope ) ) );
3460 if( arrowx < 0 ) {
3461 arrowx = 0;
3462 }
3463 if( arrowx > 6 ) {
3464 arrowx = 6;
3465 }
3466 } else {
3467 arrowx = targ.x() > curs2.x() ? 6 : 0;
3468 arrowy = static_cast<int>( 3 + 3 * ( targ.x() > curs2.x() ? slope : -slope ) );
3469 if( arrowy < 0 ) {
3470 arrowy = 0;
3471 }
3472 if( arrowy > 6 ) {
3473 arrowy = 6;
3474 }
3475 }
3476 char glyph = '*';
3477 if( targ.z() > u.posz() ) {
3478 glyph = '^';
3479 } else if( targ.z() < u.posz() ) {
3480 glyph = 'v';
3481 }
3482
3483 mvwputch( w_minimap, point( arrowx, arrowy ), c_red, glyph );
3484 }
3485 }
3486
3487 const int sight_points = g->u.overmap_sight_range( g->light_level( g->u.posz() ) );
3488 for( int i = -3; i <= 3; i++ ) {
3489 for( int j = -3; j <= 3; j++ ) {
3490 if( i > -3 && i < 3 && j > -3 && j < 3 ) {
3491 continue; // only do hordes on the border, skip inner map
3492 }
3493 const tripoint_abs_omt omp( curs2 + point( i, j ), get_levz() );
3495 if( overmap_buffer.seen( omp )
3496 && g->u.overmap_los( omp, sight_points ) ) {
3497 mvwputch( w_minimap, point( i + 3, j + 3 ), c_green,
3498 overmap_buffer.get_horde_size( omp ) > HORDE_VISIBILITY_SIZE * 2 ? 'Z' : 'z' );
3499 }
3500 }
3501 }
3502 }
3503
3505}
tripoint_abs_omt get_active_mission_target() const
Returns the target of the active mission or overmap::invalid_tripoint if there is no active mission.
Definition: avatar.cpp:207
constexpr auto & x()
Definition: coordinates.h:118
constexpr auto & z()
Definition: coordinates.h:133
constexpr auto & y()
Definition: coordinates.h:124
constexpr auto xy() const
Definition: coordinates.h:130
static constexpr tripoint_abs_omt invalid_tripoint
Dummy value, used to indicate that a point returned by a function is invalid.
Definition: overmap.h:260
bool seen(const tripoint_abs_omt &p)
const std::string & note(const tripoint_abs_omt &p)
int get_horde_size(const tripoint_abs_omt &p)
bool is_explored(const tripoint_abs_omt &p)
const oter_id & ter(const tripoint_abs_omt &p)
Returns the overmap terrain at the given OMT coordinates.
bool has_note(const tripoint_abs_omt &p)
Uses global overmap terrain coordinates.
bool has_vehicle(const tripoint_abs_omt &p)
nc_color red_background(const nc_color &c)
Definition: color.cpp:515
#define c_blue
Definition: color.h:23
#define c_black
Definition: color.h:17
#define c_light_blue
Definition: color.h:29
#define c_yellow
Definition: color.h:32
#define c_light_cyan
Definition: color.h:30
#define c_cyan
Definition: color.h:24
#define c_light_red
Definition: color.h:27
static constexpr int HORDE_VISIBILITY_SIZE
constexpr scale om
Definition: coordinates.h:34
void mvwputch_hi(const catacurses::window &w, point p, nc_color FG, int ch)
Definition: output.cpp:508
std::string get_symbol(const bool from_land_use_code=false) const
Definition: omdata.h:209
nc_color get_color(const bool from_land_use_code=false) const
Definition: omdata.h:217

References c_black, c_blue, c_brown, c_cyan, c_dark_gray, c_green, c_light_blue, c_light_cyan, c_light_gray, c_light_green, c_light_red, c_magenta, c_pink, c_red, c_white, c_yellow, draw_border(), units::fabs(), g, avatar::get_active_mission_target(), oter_t::get_color(), overmapbuffer::get_horde_size(), get_levz(), oter_t::get_symbol(), Character::global_omt_location(), overmapbuffer::has_note(), overmapbuffer::has_vehicle(), HORDE_VISIBILITY_SIZE, overmap::invalid_tripoint, overmapbuffer::is_explored(), mvwputch(), mvwputch_hi(), overmapbuffer::note(), coords::om, overmap_buffer, Character::posz(), red_background(), overmapbuffer::seen(), overmapbuffer::ter(), u, w_minimap, catacurses::werase(), catacurses::wnoutrefresh(), coords::coord_point< Point, Origin, Scale >::x(), coords::coord_point< Point, Origin, Scale >::xy(), coords::coord_point< Point, Origin, Scale >::y(), and coords::coord_point< Point, Origin, Scale >::z().

◆ draw_monster_override()

void game::draw_monster_override ( const tripoint p,
const mtype_id id,
int  count,
bool  more,
Creature::Attitude  att 
)

Definition at line 1037 of file animation.cpp.

1039{
1040}

◆ draw_panels()

void game::draw_panels ( bool  force_draw = false)

Definition at line 3128 of file game.cpp.

3129{
3130 static int previous_turn = -1;
3131 const int current_turn = to_turns<int>( calendar::turn - calendar::turn_zero );
3132 const bool draw_this_turn = current_turn > previous_turn || force_draw;
3133 auto &mgr = panel_manager::get_manager();
3134 int y = 0;
3135 const bool sidebar_right = get_option<std::string>( "SIDEBAR_POSITION" ) == "right";
3136 int spacer = get_option<bool>( "SIDEBAR_SPACERS" ) ? 1 : 0;
3137 int log_height = 0;
3138 for( const window_panel &panel : mgr.get_current_layout() ) {
3139 if( panel.get_height() != -2 && panel.toggle && panel.render() ) {
3140 log_height += panel.get_height() + spacer;
3141 }
3142 }
3143 log_height = std::max( TERMY - log_height, 3 );
3144 for( const window_panel &panel : mgr.get_current_layout() ) {
3145 if( panel.render() ) {
3146 // height clamped to window height.
3147 int h = std::min( panel.get_height(), TERMY - y );
3148 if( h == -2 ) {
3149 h = log_height;
3150 }
3151 h += spacer;
3152 if( panel.toggle && panel.render() && h > 0 ) {
3153 if( panel.always_draw || draw_this_turn ) {
3154 panel.draw( u, catacurses::newwin( h, panel.get_width(),
3155 point( sidebar_right ? TERMX - panel.get_width() : 0, y ) ) );
3156 }
3157 if( show_panel_adm ) {
3158 const std::string panel_name = _( panel.get_name() );
3159 const int panel_name_width = utf8_width( panel_name );
3160 auto label = catacurses::newwin( 1, panel_name_width, point( sidebar_right ?
3161 TERMX - panel.get_width() - panel_name_width - 1 : panel.get_width() + 1, y ) );
3162 werase( label );
3163 mvwprintz( label, point_zero, c_light_red, panel_name );
3165 label = catacurses::newwin( h, 1,
3166 point( sidebar_right ? TERMX - panel.get_width() - 1 : panel.get_width(), y ) );
3167 werase( label );
3168 if( h == 1 ) {
3170 } else {
3172 for( int i = 1; i < h - 1; i++ ) {
3174 }
3175 mvwputch( label, point( 0, h - 1 ), c_light_red, sidebar_right ? LINE_XXOO : LINE_XOOX );
3176 }
3178 }
3179 y += h;
3180 }
3181 }
3182 }
3183 previous_turn = current_turn;
3184}
bool show_panel_adm
Definition: game.h:1013
const time_point turn_zero
Represents time point 0.
Definition: calendar.cpp:26
#define LINE_XOXO
Definition: output.h:39
#define LINE_OXOX
Definition: output.h:40
#define LINE_OXXX
Definition: output.h:48
#define LINE_XOOX
Definition: output.h:44
#define LINE_XXOO
Definition: output.h:41
Struct used for storing labels (easier to json opposed to a std::map<point, std::string>)
Definition: vehicle.h:286

References _, c_light_red, panel_manager::get_manager(), LINE_OXOX, LINE_OXXX, LINE_XOOX, LINE_XOXO, LINE_XXOO, mvwprintz(), mvwputch(), catacurses::newwin(), point_zero, show_panel_adm, TERMX, TERMY, calendar::turn, calendar::turn_zero, u, utf8_width(), catacurses::werase(), and catacurses::wnoutrefresh().

Referenced by draw().

◆ draw_pixel_minimap()

void game::draw_pixel_minimap ( const catacurses::window w)

Definition at line 3186 of file game.cpp.

3187{
3188 w_pixel_minimap = w;
3189}

References w_pixel_minimap.

◆ draw_radiation_override()

void game::draw_radiation_override ( const tripoint p,
int  rad 
)

Definition at line 914 of file animation.cpp.

915{
916}

◆ draw_sct()

void game::draw_sct ( )

Definition at line 865 of file animation.cpp.

866{
867 draw_sct_curses( *this );
868}
void draw_sct_curses(const game &g)
Definition: animation.cpp:832

References anonymous_namespace{animation.cpp}::draw_sct_curses().

Referenced by get_player_input().

◆ draw_ter() [1/2]

void game::draw_ter ( bool  draw_sounds = true)

Definition at line 3242 of file game.cpp.

3243{
3245 draw_sounds );
3246}
bool is_looking
Definition: game.h:224

References draw_ter(), is_looking, Character::pos(), u, and player::view_offset.

Referenced by draw(), and draw_ter().

◆ draw_ter() [2/2]

void game::draw_ter ( const tripoint center,
bool  looking = false,
bool  draw_sounds = true 
)

Definition at line 3248 of file game.cpp.

3249{
3251
3252 m.draw( w_terrain, center );
3253
3254 if( draw_sounds ) {
3256 }
3257
3258 for( Creature &critter : all_creatures() ) {
3259 draw_critter( critter, center );
3260 }
3261
3262 if( !destination_preview.empty() && u.view_offset.z == 0 ) {
3263 // Draw auto-move preview trail
3264 const tripoint &final_destination = destination_preview.back();
3265 tripoint line_center = u.pos() + u.view_offset;
3266 draw_line( final_destination, line_center, destination_preview, true );
3267 mvwputch( w_terrain, final_destination.xy() - u.view_offset.xy() + point( POSX - u.posx(),
3268 POSY - u.posy() ), c_white, 'X' );
3269 }
3270
3271 if( u.controlling_vehicle && !looking ) {
3272 draw_veh_dir_indicator( false );
3273 draw_veh_dir_indicator( true );
3274 }
3275 // Place the cursor over the player as is expected by screen readers.
3276 wmove( w_terrain, -center.xy() + g->u.pos().xy() + point( POSX, POSY ) );
3277}
int posx() const override
Definition: character.h:795
int posy() const override
Definition: character.h:798
void draw_critter(const Creature &critter, const tripoint &center)
Definition: game.cpp:3224
Creature_range all_creatures()
Returns an anonymous range that contains all creatures.
Definition: game.cpp:12036
std::vector< tripoint > destination_preview
Definition: game.h:1065
void draw_veh_dir_indicator(bool next)
Definition: game.cpp:3294
void draw_line(const tripoint &p, const tripoint &center_point, const std::vector< tripoint > &points, bool noreveal=false)
Definition: animation.cpp:737
void draw(const catacurses::window &w, const tripoint &center)
Draw a visible part of the map into w.
Definition: map.cpp:5840
static void draw_footsteps(const catacurses::window &window, const tripoint &offset)
Definition: game.cpp:2914
void wmove(const window &win, point p)
Definition: ncurses_def.cpp:99

References all_creatures(), c_white, center, Character::controlling_vehicle, destination_preview, map::draw(), draw_critter(), draw_footsteps(), draw_line(), draw_veh_dir_indicator(), g, m, mvwputch(), Character::pos(), Character::posx(), POSX, Character::posy(), POSY, ter_view_p, u, player::view_offset, w_terrain, catacurses::wmove(), tripoint::xy(), and tripoint::z.

◆ draw_terrain_override()

void game::draw_terrain_override ( const tripoint p,
const ter_id id 
)

Definition at line 927 of file animation.cpp.

928{
929}

◆ draw_trail_to_square()

void game::draw_trail_to_square ( const tripoint t,
bool  bDrawX 
)

Definition at line 7023 of file game.cpp.

7024{
7025 ::draw_trail( u.pos(), u.pos() + t, bDrawX );
7026}
static void draw_trail(const tripoint &start, const tripoint &end, bool bDrawX)
Definition: game.cpp:6993

References draw_trail(), Character::pos(), and u.

◆ draw_trap_override()

void game::draw_trap_override ( const tripoint p,
const trap_id id 
)

Definition at line 966 of file animation.cpp.

967{
968}

◆ draw_veh_dir_indicator()

void game::draw_veh_dir_indicator ( bool  next)

Definition at line 3294 of file game.cpp.

3295{
3296 if( const std::optional<tripoint> indicator_offset = get_veh_dir_indicator_location( next ) ) {
3297 auto col = next ? c_white : c_dark_gray;
3298 mvwputch( w_terrain, indicator_offset->xy() - u.view_offset.xy() + point( POSX, POSY ), col, 'X' );
3299 }
3300}
std::optional< tripoint > get_veh_dir_indicator_location(bool next) const
Returns the location where the indicator should go relative to the reality bubble,...
Definition: game.cpp:3279

References c_dark_gray, c_white, get_veh_dir_indicator_location(), mvwputch(), POSX, POSY, u, player::view_offset, w_terrain, and tripoint::xy().

Referenced by draw_ter().

◆ draw_vpart_override()

void game::draw_vpart_override ( const tripoint p,
const vpart_id id,
int  part_mod,
units::angle  veh_dir,
bool  hilite,
point  mount 
)

Definition at line 1009 of file animation.cpp.

1011{
1012}

◆ draw_weather()

void game::draw_weather ( const weather_printable wPrint)

Definition at line 824 of file animation.cpp.

825{
827}
void draw_weather_curses(const catacurses::window &win, const weather_printable &w)
Definition: animation.cpp:805

References anonymous_namespace{animation.cpp}::draw_weather_curses(), and w_terrain.

Referenced by get_player_input().

◆ draw_zones()

void game::draw_zones ( const tripoint start,
const tripoint end,
const tripoint offset 
)

Definition at line 900 of file animation.cpp.

901{
902 draw_zones_curses( w_terrain, start, end, offset );
903}
void draw_zones_curses(const catacurses::window &w, const tripoint &start, const tripoint &end, const tripoint &offset)
Definition: animation.cpp:873

References anonymous_namespace{animation.cpp}::draw_zones_curses(), and w_terrain.

◆ drop()

void game::drop ( )
private

Definition at line 8071 of file game.cpp.

8072{
8074}
void drop(item_location loc, const tripoint &where)
Drops an item to the specified location.
Definition: character.cpp:2453
drop_locations multidrop(player &p)
Select items to drop.

References Character::drop(), game_menus::inv::multidrop(), Character::pos(), and u.

Referenced by handle_action().

◆ drop_in_direction()

void game::drop_in_direction ( )
private

Definition at line 8076 of file game.cpp.

8077{
8078 if( const std::optional<tripoint> pnt = choose_adjacent( _( "Drop where?" ) ) ) {
8079 u.drop( game_menus::inv::multidrop( u ), *pnt );
8080 }
8081}

References _, choose_adjacent(), Character::drop(), game_menus::inv::multidrop(), and u.

Referenced by handle_action().

◆ dump_stats()

bool game::dump_stats ( const std::string &  what,
dump_mode  mode,
const std::vector< std::string > &  opts 
)

write statistics to stdout and

Returns
true if successful

Definition at line 40 of file dump.cpp.

42{
43 try {
45 } catch( const std::exception &err ) {
46 std::cerr << "Error loading data from json: " << err.what() << std::endl;
47 return false;
48 }
49
50 std::vector<std::string> header;
51 std::vector<std::vector<std::string>> rows;
52
53 int scol = 0; // sorting column
54
55 std::map<std::string, standard_npc> test_npcs;
56 test_npcs[ "S1" ] = standard_npc( "S1", { 0, 0, 2 }, { "gloves_survivor", "mask_lsurvivor" },
57 4, 8, 10, 8, 10 /* DEX 10, PER 10 */ );
58 test_npcs[ "S2" ] = standard_npc( "S2", { 0, 0, 3 }, { "gloves_fingerless", "sunglasses" },
59 4, 8, 8, 8, 10 /* PER 10 */ );
60 test_npcs[ "S3" ] = standard_npc( "S3", { 0, 0, 4 }, { "gloves_plate", "helmet_plate" },
61 4, 10, 8, 8, 8 /* STAT 10 */ );
62 test_npcs[ "S4" ] = standard_npc( "S4", { 0, 0, 5 }, {}, 0, 8, 10, 8, 10 /* DEX 10, PER 10 */ );
63 test_npcs[ "S5" ] = standard_npc( "S5", { 0, 0, 6 }, {}, 4, 8, 10, 8, 10 /* DEX 10, PER 10 */ );
64 test_npcs[ "S6" ] = standard_npc( "S6", { 0, 0, 7 }, { "gloves_hsurvivor", "mask_hsurvivor" },
65 4, 8, 10, 8, 10 /* DEX 10, PER 10 */ );
66
67 std::map<std::string, item> test_items;
68 test_items[ "G1" ] = item( "glock_19" ).ammo_set( itype_id( "9mm" ) );
69 test_items[ "G2" ] = item( "hk_mp5" ).ammo_set( itype_id( "9mm" ) );
70 test_items[ "G3" ] = item( "ar15" ).ammo_set( itype_id( "223" ) );
71 test_items[ "G4" ] = item( "remington_700" ).ammo_set( itype_id( "270" ) );
72 test_items[ "G4" ].put_in( item( "rifle_scope" ) );
73
74 if( what == "AMMO" ) {
75 header = {
76 "Name", "Ammo", "Volume", "Weight", "Stack",
77 "Range", "Dispersion", "Recoil", "Damage", "Pierce", "Damage multiplier"
78 };
79 auto dump = [&rows]( const item & obj ) {
80 std::vector<std::string> r;
81 r.push_back( obj.tname( 1, false ) );
82 r.push_back( obj.ammo_type().str() );
83 r.push_back( std::to_string( obj.volume() / units::legacy_volume_factor ) );
84 r.push_back( std::to_string( to_gram( obj.weight() ) ) );
85 r.push_back( std::to_string( obj.type->stack_size ) );
86 r.push_back( std::to_string( obj.type->ammo->range ) );
87 r.push_back( std::to_string( obj.type->ammo->dispersion ) );
88 r.push_back( std::to_string( obj.type->ammo->recoil ) );
89 damage_instance damage = obj.type->ammo->damage;
90 r.push_back( std::to_string( damage.total_damage() ) );
91 r.push_back( std::to_string( damage.empty() ? 0 : ( *damage.begin() ).res_pen ) );
92 rows.push_back( r );
93 };
94 for( const itype *e : item_controller->all() ) {
95 if( e->ammo ) {
96 dump( item( e, calendar::turn, item::solitary_tag {} ) );
97 }
98 }
99
100 } else if( what == "ARMOR" ) {
101 header = {
102 "Name", "Encumber (fit)", "Warmth", "Weight", "Storage", "Coverage", "Bash", "Cut", "Bullet", "Acid", "Fire"
103 };
104 auto dump = [&rows]( const item & obj ) {
105 std::vector<std::string> r;
106 r.push_back( obj.tname( 1, false ) );
107 r.push_back( std::to_string( obj.get_encumber( g->u ) ) );
108 r.push_back( std::to_string( obj.get_warmth() ) );
109 r.push_back( std::to_string( to_gram( obj.weight() ) ) );
110 r.push_back( std::to_string( obj.get_storage() / units::legacy_volume_factor ) );
111 r.push_back( std::to_string( obj.get_coverage() ) );
112 r.push_back( std::to_string( obj.bash_resist() ) );
113 r.push_back( std::to_string( obj.cut_resist() ) );
114 r.push_back( std::to_string( obj.bullet_resist() ) );
115 r.push_back( std::to_string( obj.acid_resist() ) );
116 r.push_back( std::to_string( obj.fire_resist() ) );
117 rows.push_back( r );
118 };
119
120 body_part bp = opts.empty() ? num_bp : get_body_part_token( opts.front() );
121
122 for( const itype *e : item_controller->all() ) {
123 if( e->armor ) {
124 item obj( e );
125 if( bp == num_bp || obj.covers( bp ) ) {
126 if( obj.has_flag( flag_VARSIZE ) ) {
127 obj.set_flag( "FIT" );
128 }
129 dump( obj );
130 }
131 }
132 }
133
134 } else if( what == "EDIBLE" ) {
135 header = {
136 "Name", "Volume", "Weight", "Stack", "Calories", "Quench", "Healthy"
137 };
138 for( const auto &v : vitamin::all() ) {
139 header.push_back( v.second.name() );
140 }
141 auto dump = [&rows]( const item & obj ) {
142 std::vector<std::string> r;
143 r.push_back( obj.tname( 1, false ) );
144 r.push_back( std::to_string( obj.volume() / units::legacy_volume_factor ) );
145 r.push_back( std::to_string( to_gram( obj.weight() ) ) );
146 r.push_back( std::to_string( obj.type->stack_size ) );
147 r.push_back( std::to_string( obj.get_comestible()->default_nutrition.kcal ) );
148 r.push_back( std::to_string( obj.get_comestible()->quench ) );
149 r.push_back( std::to_string( obj.get_comestible()->healthy ) );
150 auto vits = obj.get_comestible()->default_nutrition.vitamins;
151 for( const auto &v : vitamin::all() ) {
152 r.push_back( std::to_string( vits[ v.first ] ) );
153 }
154 rows.push_back( r );
155 };
156
157 for( const itype *e : item_controller->all() ) {
159
160 if( food.is_food() && g->u.can_eat( food ).success() ) {
161 dump( food );
162 }
163 }
164
165 } else if( what == "GUN" ) {
166 header = {
167 "Name", "Ammo", "Volume", "Weight", "Capacity",
168 "Range", "Dispersion", "Effective recoil", "Damage", "Pierce",
169 "Aim time", "Effective range", "Snapshot range", "Max range"
170 };
171
172 std::set<std::string> locations;
173 for( const itype *e : item_controller->all() ) {
174 if( e->gun ) {
175 std::transform( e->gun->valid_mod_locations.begin(),
176 e->gun->valid_mod_locations.end(),
177 std::inserter( locations, locations.begin() ),
178 []( const std::pair<gunmod_location, int> &q ) {
179 return q.first.name();
180 } );
181 }
182 }
183 for( const auto &e : locations ) {
184 header.push_back( e );
185 }
186
187 auto dump = [&rows, &locations]( const standard_npc & who, const item & obj ) {
188 std::vector<std::string> r;
189 r.push_back( obj.tname( 1, false ) );
190 r.push_back( !obj.ammo_types().empty() ? enumerate_as_string( obj.ammo_types().begin(),
191 obj.ammo_types().end(), []( const ammotype & at ) {
192 return at.str();
194 r.push_back( std::to_string( obj.volume() / units::legacy_volume_factor ) );
195 r.push_back( std::to_string( to_gram( obj.weight() ) ) );
196 r.push_back( std::to_string( obj.ammo_capacity() ) );
197 r.push_back( std::to_string( obj.gun_range() ) );
198 r.push_back( std::to_string( obj.gun_dispersion() ) );
199 r.push_back( std::to_string( obj.gun_recoil() ) );
200 damage_instance damage = obj.gun_damage();
201 r.push_back( std::to_string( damage.total_damage() ) );
202 r.push_back( std::to_string( damage.empty() ? 0 : ( *damage.begin() ).res_pen ) );
203
204 r.push_back( std::to_string( ranged::gun_engagement_moves( who, obj ) ) );
205
206 for( const auto &e : locations ) {
207 const auto &vml = obj.type->gun->valid_mod_locations;
208 const auto iter = vml.find( e );
209 r.push_back( std::to_string( iter != vml.end() ? iter->second : 0 ) );
210 }
211 rows.push_back( r );
212 };
213 for( const itype *e : item_controller->all() ) {
214 if( e->gun ) {
215 item gun( e );
216 if( !gun.magazine_integral() ) {
217 gun.put_in( item( gun.magazine_default() ) );
218 }
219 gun.ammo_set( gun.ammo_default( false ), gun.ammo_capacity() );
220
221 dump( test_npcs[ "S1" ], gun );
222
223 if( gun.type->gun->barrel_length > 0_ml ) {
224 gun.put_in( item( "barrel_small" ) );
225 dump( test_npcs[ "S1" ], gun );
226 }
227 }
228 }
229
230 } else if( what == "RECIPE" ) {
231
232 // optionally filter recipes to include only those using specified skills
233 recipe_subset dict;
234 for( const auto &r : recipe_dict ) {
235 if( opts.empty() || std::any_of( opts.begin(), opts.end(), [&r]( const std::string & s ) {
236 if( r.second.skill_used == skill_id( s ) && r.second.difficulty > 0 ) {
237 return true;
238 }
239 const auto iter = r.second.required_skills.find( skill_id( s ) );
240 return iter != r.second.required_skills.end() && iter->second > 0;
241 } ) ) {
242 dict.include( &r.second );
243 }
244 }
245
246 // only consider skills that are required by at least one recipe
247 std::vector<Skill> sk;
248 std::copy_if( Skill::skills.begin(), Skill::skills.end(),
249 std::back_inserter( sk ), [&dict]( const Skill & s ) {
250 return std::any_of( dict.begin(), dict.end(), [&s]( const recipe * r ) {
251 return r->skill_used == s.ident() ||
252 r->required_skills.find( s.ident() ) != r->required_skills.end();
253 } );
254 } );
255
256 header = { "Result" };
257
258 for( const auto &e : sk ) {
259 header.push_back( e.ident().str() );
260 }
261
262 for( const recipe *e : dict ) {
263 std::vector<std::string> r;
264 r.push_back( e->result_name() );
265 for( const auto &s : sk ) {
266 if( e->skill_used == s.ident() ) {
267 r.push_back( std::to_string( e->difficulty ) );
268 } else {
269 auto iter = e->required_skills.find( s.ident() );
270 r.push_back( std::to_string( iter != e->required_skills.end() ? iter->second : 0 ) );
271 }
272 }
273 rows.push_back( r );
274 }
275
276 } else if( what == "VEHICLE" ) {
277 header = {
278 "Name", "Weight (empty)", "Weight (fueled)",
279 "Max velocity (mph)", "Safe velocity (mph)", "Acceleration (mph/turn)",
280 "Aerodynamics coeff", "Rolling coeff", "Static Drag", "Offroad %"
281 };
282 auto dump = [&rows]( const vproto_id & obj ) {
283 vehicle veh_empty( obj, 0, 0 );
284 vehicle veh_fueled( obj, 100, 0 );
285
286 std::vector<std::string> r;
287 r.push_back( veh_empty.name );
288 r.push_back( std::to_string( to_kilogram( veh_empty.total_mass() ) ) );
289 r.push_back( std::to_string( to_kilogram( veh_fueled.total_mass() ) ) );
290 r.push_back( std::to_string( veh_fueled.max_velocity() / 100 ) );
291 r.push_back( std::to_string( veh_fueled.safe_velocity() / 100 ) );
292 r.push_back( std::to_string( veh_fueled.acceleration() / 100 ) );
293 r.push_back( std::to_string( veh_fueled.coeff_air_drag() ) );
294 r.push_back( std::to_string( veh_fueled.coeff_rolling_drag() ) );
295 r.push_back( std::to_string( veh_fueled.static_drag( false ) ) );
296 r.push_back( std::to_string( static_cast<int>( 50 *
297 veh_fueled.k_traction( veh_fueled.wheel_area() ) ) ) );
298 rows.push_back( r );
299 };
300 for( auto &e : vehicle_prototype::get_all() ) {
301 dump( e );
302 }
303
304 } else if( what == "VPART" ) {
305 header = {
306 "Name", "Location", "Weight", "Size"
307 };
308 auto dump = [&rows]( const vpart_info & obj ) {
309 std::vector<std::string> r;
310 r.push_back( obj.name() );
311 r.push_back( obj.location );
312 int w = std::ceil( to_gram( item( obj.item ).weight() ) / 1000.0 );
313 r.push_back( std::to_string( w ) );
314 r.push_back( std::to_string( obj.size / units::legacy_volume_factor ) );
315 rows.push_back( r );
316 };
317 for( const auto &e : vpart_info::all() ) {
318 dump( e.second );
319 }
320
321 } else {
322 std::cerr << "unknown argument: " << what << std::endl;
323 return false;
324 }
325
326 rows.erase( std::remove_if( rows.begin(), rows.end(), []( const std::vector<std::string> &e ) {
327 return e.empty();
328 } ), rows.end() );
329
330 if( scol >= 0 ) {
331 std::sort( rows.begin(), rows.end(), [&scol]( const std::vector<std::string> &lhs,
332 const std::vector<std::string> &rhs ) {
333 return localized_compare( lhs[ scol ], rhs[ scol ] );
334 } );
335 }
336
337 rows.erase( std::unique( rows.begin(), rows.end() ), rows.end() );
338
339 switch( mode ) {
340 case dump_mode::TSV:
341 rows.insert( rows.begin(), header );
342 for( const auto &r : rows ) {
343 // NOLINTNEXTLINE(cata-text-style): using tab to align the output
344 std::copy( r.begin(), r.end() - 1, std::ostream_iterator<std::string>( std::cout, "\t" ) );
345 std::cout << r.back() << "\n";
346 }
347 break;
348
349 case dump_mode::HTML:
350 std::cout << "<table>";
351
352 std::cout << "<thead>";
353 std::cout << "<tr>";
354 for( const auto &col : header ) {
355 std::cout << "<th>" << col << "</th>";
356 }
357 std::cout << "</tr>";
358 std::cout << "</thead>";
359
360 std::cout << "<tdata>";
361 for( const auto &r : rows ) {
362 std::cout << "<tr>";
363 for( const auto &col : r ) {
364 std::cout << "<td>" << col << "</td>";
365 }
366 std::cout << "</tr>";
367 }
368 std::cout << "</tdata>";
369
370 std::cout << "</table>";
371 break;
372 }
373
374 return true;
375}
body_part get_body_part_token(const std::string &id)
Returns the matching body_part token from the corresponding body_part string.
Definition: bodypart.cpp:180
body_part
Definition: bodypart.h:41
std::string to_string(const time_duration &d)
Returns a string showing a duration.
Definition: calendar.cpp:327
Definition: skill.h:33
static std::vector< Skill > skills
Definition: skill.h:49
const skill_id & ident() const
Definition: skill.h:65
units::mass weight(bool include_contents=true, bool integral=false) const
Definition: item.cpp:4985
void put_in(const item &payload)
Puts the given item into this one, no checks are performed.
Definition: item.cpp:1000
item & ammo_set(const itype_id &ammo, int qty=-1)
Filter setting the ammo for this instance Any existing ammo is removed.
Definition: item.cpp:595
std::set< constrecipe * >::const_iterator begin() const
std::set< constrecipe * >::const_iterator end() const
void include(const recipe *r, int custom_difficulty=-1)
Include a recipe to the subset.
Definition: recipe.h:35
An NPC with standard stats.
Definition: npc.h:1363
static const std::map< vitamin_id, vitamin > & all()
Get all currently loaded vitamins.
Definition: vitamin.cpp:98
static const std::map< vpart_id, vpart_info > & all()
Definition: veh_type.cpp:696
static const std::string flag_VARSIZE("VARSIZE")
std::unique_ptr< Item_factory > item_controller
void transform(player &p, const tripoint &pos)
Transform the examined object into the object specified by its transforms_into property.
Definition: iexamine.cpp:1556
void load_core_bn_modfiles()
Load & finalize modlist that consists of single vanilla BN core "mod".
Definition: init.cpp:922
int gun_engagement_moves(const Character &who, const item &gun, int target=0, int start=MAX_RECOIL)
How many moves does it take to aim gun to the target accuracy.
Definition: ranged.cpp:584
static constexpr volume legacy_volume_factor
Definition: units_volume.h:50
constexpr value_type to_gram(const quantity< value_type, mass_in_milligram_tag > &v)
Definition: units_mass.h:68
constexpr value_type to_kilogram(const quantity< value_type, mass_in_milligram_tag > &v)
Definition: units_mass.h:74
std::string enumerate_as_string(const _Container &values, enumeration_conjunction conj=enumeration_conjunction::and_)
Definition: output.h:637
recipe_dictionary recipe_dict
float total_damage() const
Definition: damage.cpp:75
std::vector< damage_unit >::iterator begin()
Definition: damage.cpp:120
bool empty() const
Definition: damage.cpp:88
Default (or randomized) charges except if counted by charges then only one charge.
Definition: item.h:230
Definition: itype.h:805
static std::vector< vproto_id > get_all()
Definition: veh_type.cpp:1158

References vitamin::all(), item::ammo_capacity(), item::ammo_default(), item::ammo_set(), damage_instance::begin(), item::covers(), damage_instance::empty(), enumerate_as_string(), flag_VARSIZE(), g, get_body_part_token(), itype::gun, ranged::gun_engagement_moves(), item::has_flag(), Skill::ident(), recipe_subset::include(), item_controller, itype_id, units::legacy_volume_factor, init::load_core_bn_modfiles(), anonymous_namespace{overmap_location.cpp}::locations, item::magazine_default(), item::magazine_integral(), none, num_bp, item::put_in(), recipe_dict, item::set_flag(), Skill::skills, units::to_gram(), to_string(), damage_instance::total_damage(), iexamine::transform(), calendar::turn, and item::type.

◆ events()

event_bus & game::events ( )

Definition at line 2713 of file game.cpp.

2714{
2715 return *event_bus_ptr;
2716}
pimpl< event_bus > event_bus_ptr
Definition: game.h:951

References event_bus_ptr.

Referenced by cleanup_at_end(), and game().

◆ exam_vehicle()

void game::exam_vehicle ( vehicle veh,
point  cp = point_zero 
)

open vehicle interaction screen

Definition at line 5001 of file game.cpp.

5002{
5003 if( veh.magic ) {
5004 add_msg( m_info, _( "This is your %s" ), veh.name );
5005 return;
5006 }
5007 auto act = veh_interact::run( veh, c );
5008 if( act ) {
5009 u.moves = 0;
5011 }
5012}
static player_activity run(vehicle &veh, point p)
bool magic
Definition: vehicle.h:1598
constexpr double c
Definition: magic.cpp:1032
activity_id act
Definition: sounds.cpp:76

References _, act, add_msg(), Character::assign_activity(), c, m_info, vehicle::magic, Creature::moves, vehicle::name, veh_interact::run(), and u.

◆ examine() [1/2]

void game::examine ( )
private

Definition at line 5392 of file game.cpp.

5393{
5394 // if we are driving a vehicle, examine the
5395 // current tile without asking.
5396 const optional_vpart_position vp = m.veh_at( u.pos() );
5397 if( vp && vp->vehicle().player_in_control( u ) ) {
5398 examine( u.pos() );
5399 return;
5400 }
5401
5402 const std::optional<tripoint> examp_ = choose_adjacent_highlight( _( "Examine where?" ),
5403 _( "There is nothing that can be examined nearby." ),
5404 ACTION_EXAMINE, false );
5405 if( !examp_ ) {
5406 return;
5407 }
5408 u.manual_examine = true;
5409 examine( *examp_ );
5410 u.manual_examine = false;
5411}
std::optional< tripoint > choose_adjacent_highlight(const std::string &message, const std::string &failure_message, const action_id action, bool allow_vertical)
Request player input of adjacent tile with highlighting, possibly on different z-level.
Definition: action.cpp:1004
@ ACTION_EXAMINE
Examine or pick up items from adjacent square.
Definition: action.h:101
void examine()
Definition: game.cpp:5392
bool manual_examine
Definition: player.h:249

References _, ACTION_EXAMINE, choose_adjacent_highlight(), examine(), m, player::manual_examine, Character::pos(), u, and map::veh_at().

Referenced by examine(), and handle_action().

◆ examine() [2/2]

void game::examine ( const tripoint p)
private

Definition at line 5480 of file game.cpp.

5481{
5482 if( disable_robot( examp ) ) {
5483 return;
5484 }
5485
5486 Creature *c = critter_at( examp );
5487 if( c != nullptr ) {
5488 monster *mon = dynamic_cast<monster *>( c );
5489 if( mon != nullptr ) {
5490 if( mon->battery_item && mon->has_effect( effect_pet ) ) {
5491 const itype &type = *mon->type->mech_battery;
5492 int max_charge = type.magazine->capacity;
5493 float charge_percent;
5494 if( mon->battery_item ) {
5495 charge_percent = static_cast<float>( mon->battery_item->ammo_remaining() ) / max_charge * 100;
5496 } else {
5497 charge_percent = 0.0;
5498 }
5499 add_msg( _( "There is a %s. Battery level: %d%%" ), mon->get_name(),
5500 static_cast<int>( charge_percent ) );
5501 } else {
5502 add_msg( _( "There is a %s." ), mon->get_name() );
5503 }
5504
5505
5506 if( mon->has_effect( effect_pet ) && !u.is_mounted() ) {
5507 if( monexamine::pet_menu( *mon ) ) {
5508 return;
5509 }
5510 } else if( mon->has_flag( MF_RIDEABLE_MECH ) && !mon->has_effect( effect_pet ) ) {
5511 if( monexamine::mech_hack( *mon ) ) {
5512 return;
5513 }
5514 } else if( mon->has_flag( MF_PAY_BOT ) ) {
5515 if( monexamine::pay_bot( *mon ) ) {
5516 return;
5517 }
5518 } else if( mon->attitude_to( u ) == Creature::A_FRIENDLY && !u.is_mounted() ) {
5519 if( monexamine::mfriend_menu( *mon ) ) {
5520 return;
5521 }
5522 }
5523 } else if( u.is_mounted() ) {
5524 add_msg( m_warning, _( "You cannot do that while mounted." ) );
5525 }
5526 npc *np = dynamic_cast<npc *>( c );
5527 if( np != nullptr && !u.is_mounted() ) {
5528 if( npc_menu( *np ) ) {
5529 return;
5530 }
5531 } else if( np != nullptr && u.is_mounted() ) {
5532 add_msg( m_warning, _( "You cannot do that while mounted." ) );
5533 }
5534 }
5535
5536 const optional_vpart_position vp = m.veh_at( examp );
5537 if( vp && u.is_mounted() ) {
5538 if( !u.mounted_creature->has_flag( MF_RIDEABLE_MECH ) ) {
5539 add_msg( m_warning, _( "You cannot interact with a vehicle while mounted." ) );
5540 } else {
5541 vp->vehicle().interact_with( examp, vp->part_index() );
5542 return;
5543 }
5544 } else if( vp && !u.is_mounted() ) {
5545 vp->vehicle().interact_with( examp, vp->part_index() );
5546 return;
5547 }
5548
5549 if( m.has_flag( "CONSOLE", examp ) && !u.is_mounted() ) {
5550 use_computer( examp );
5551 return;
5552 } else if( m.has_flag( "CONSOLE", examp ) && u.is_mounted() ) {
5553 add_msg( m_warning, _( "You cannot use a console while mounted." ) );
5554 }
5555 const furn_t &xfurn_t = m.furn( examp ).obj();
5556 const ter_t &xter_t = m.ter( examp ).obj();
5557
5558 const tripoint player_pos = u.pos();
5559
5560 if( m.has_furn( examp ) && !u.is_mounted() ) {
5561 xfurn_t.examine( u, examp );
5562 } else if( m.has_furn( examp ) && u.is_mounted() ) {
5563 add_msg( m_warning, _( "You cannot do that while mounted." ) );
5564 } else {
5565 if( !u.is_mounted() ) {
5566 xter_t.examine( u, examp );
5567 } else if( u.is_mounted() && xter_t.examine == &iexamine::none ) {
5568 xter_t.examine( u, examp );
5569 } else {
5570 add_msg( m_warning, _( "You cannot do that while mounted." ) );
5571 }
5572 }
5573
5574 // Did the player get moved? Bail out if so; our examp probably
5575 // isn't valid anymore.
5576 if( player_pos != u.pos() ) {
5577 return;
5578 }
5579
5580 bool none = true;
5581 if( xter_t.examine != &iexamine::none || xfurn_t.examine != &iexamine::none ) {
5582 none = false;
5583 }
5584
5585 if( !m.tr_at( examp ).is_null() && !u.is_mounted() ) {
5586 iexamine::trap( u, examp );
5587 } else if( !m.tr_at( examp ).is_null() && u.is_mounted() ) {
5588 add_msg( m_warning, _( "You cannot do that while mounted." ) );
5589 }
5590
5591 // In case of teleport trap or somesuch
5592 if( player_pos != u.pos() ) {
5593 return;
5594 }
5595
5596 // Feedback for fire lasting time, this can be judged while mounted
5597 const std::string fire_fuel = get_fire_fuel_string( examp );
5598 if( !fire_fuel.empty() ) {
5599 add_msg( fire_fuel );
5600 }
5601
5602 if( m.has_flag( "SEALED", examp ) ) {
5603 if( none ) {
5604 if( m.has_flag( "UNSTABLE", examp ) ) {
5605 add_msg( _( "The %s is too unstable to remove anything." ), m.name( examp ) );
5606 } else {
5607 add_msg( _( "The %s is firmly sealed." ), m.name( examp ) );
5608 }
5609 }
5610 } else {
5611 //examp has no traps, is a container and doesn't have a special examination function
5612 if( m.tr_at( examp ).is_null() && m.i_at( examp ).empty() &&
5613 m.has_flag( "CONTAINER", examp ) && none ) {
5614 add_msg( _( "It is empty." ) );
5615 } else if( ( m.has_flag( TFLAG_FIRE_CONTAINER, examp ) &&
5616 xfurn_t.examine == &iexamine::fireplace ) ||
5617 xfurn_t.examine == &iexamine::workbench ||
5618 xfurn_t.examine == &iexamine::transform ) {
5619 return;
5620 } else {
5622 if( !u.is_mounted() ) {
5623 pickup::pick_up( examp, 0 );
5624 }
5625 }
5626 }
5627}
shared_ptr_fast< monster > mounted_creature
Definition: character.h:1615
@ A_FRIENDLY
Definition: creature.h:169
void use_computer(const tripoint &p)
Checks to see if a player can use a computer (not illiterate, etc.) and uses if able.
Definition: game.cpp:4512
bool disable_robot(const tripoint &p)
If there is a robot (that can be disabled), query the player and try to disable it.
Definition: game.cpp:8657
bool npc_menu(npc &who)
Returns true if the menu handled stuff and player shouldn't do anything else.
Definition: game.cpp:5283
bool empty() const
Definition: item_stack.cpp:15
bool has_furn(const tripoint &p) const
Definition: map.cpp:1408
const trap & tr_at(const tripoint &p) const
Definition: map.cpp:5258
ter_id ter(const tripoint &p) const
Definition: map.cpp:1563
Attitude attitude_to(const Creature &other) const override
Attitude (of this creature) towards another creature.
Definition: monster.cpp:1045
cata::value_ptr< item > battery_item
Definition: monster.h:465
std::string get_name() const override
Definition: monster.cpp:484
static std::string get_fire_fuel_string(const tripoint &examp)
Definition: game.cpp:5413
@ TFLAG_FIRE_CONTAINER
Definition: mapdata.h:294
void fireplace(player &p, const tripoint &examp)
Definition: iexamine.cpp:2833
void workbench(player &p, const tripoint &examp)
Definition: iexamine.cpp:6136
void none(player &p, const tripoint &examp)
Nothing player can interact with here.
Definition: iexamine.cpp:252
void trap(player &p, const tripoint &examp)
Definition: iexamine.cpp:3732
bool pet_menu(monster &z)
Definition: monexamine.cpp:67
bool mech_hack(monster &z)
Definition: monexamine.cpp:433
bool mfriend_menu(monster &z)
Definition: monexamine.cpp:507
bool pay_bot(monster &z)
Definition: monexamine.cpp:466
void pick_up(const tripoint &p, int min, from_where get_items_from=prompt)
Pick up items; 'g' or ',' or via examine()
Definition: pickup.cpp:576
iexamine_function examine
Definition: mapdata.h:404
itype_id mech_battery
If this monster is a rideable mech it needs a power source battery type.
Definition: mtype.h:373
Definition: mapdata.h:463
bool is_null() const
Whether this is the null-traps, aka no trap at all.
Definition: trap.cpp:245

References _, Creature::A_FRIENDLY, add_msg(), monster::attitude_to(), monster::battery_item, c, critter_at(), disable_robot(), effect_pet, item_stack::empty(), map_data_common_t::examine, iexamine::fireplace(), map::furn(), get_fire_fuel_string(), monster::get_name(), Creature::has_effect(), map::has_flag(), monster::has_flag(), map::has_furn(), map::i_at(), Character::is_mounted(), trap::is_null(), m, m_warning, mtype::mech_battery, monexamine::mech_hack(), MF_PAY_BOT, MF_RIDEABLE_MECH, monexamine::mfriend_menu(), Character::mounted_creature, map::name(), none, iexamine::none(), npc_menu(), int_id< T >::obj(), monexamine::pay_bot(), monexamine::pet_menu(), pickup::pick_up(), Character::pos(), sounds::process_sound_markers(), map::ter(), TFLAG_FIRE_CONTAINER, map::tr_at(), iexamine::transform(), iexamine::trap(), type, monster::type, u, use_computer(), map::veh_at(), and iexamine::workbench().

◆ extended_description()

void game::extended_description ( const tripoint p)

Long description of (visible) things at tile.

Definition at line 51 of file descriptions.cpp.

52{
54 const int top = 3;
55 int width = 0;
56 catacurses::window w_head;
57 catacurses::window w_main;
58 ui.on_screen_resize( [&]( ui_adaptor & ui ) {
59 const int left = 0;
60 const int right = TERMX;
61 const int bottom = TERMY;
62 width = right - left;
63 const int height = bottom - top;
64 w_head = catacurses::newwin( top, TERMX, point_zero );
65 w_main = catacurses::newwin( height, width, point( left, top ) );
66 ui.position( point_zero, point( TERMX, TERMY ) );
67 } );
68 ui.mark_resize();
69
70 // Default to critter (if any), furniture (if any), then terrain.
72 if( seen_critter( *this, p ) != nullptr ) {
74 } else if( get_map().has_furn( p ) ) {
76 }
77
78 std::string action;
79 input_context ctxt( "EXTENDED_DESCRIPTION" );
80 ctxt.register_action( "CREATURE" );
81 ctxt.register_action( "FURNITURE" );
82 ctxt.register_action( "TERRAIN" );
83 ctxt.register_action( "CONFIRM" );
84 ctxt.register_action( "QUIT" );
85 ctxt.register_action( "HELP_KEYBINDINGS" );
86
87 ui.on_redraw( [&]( const ui_adaptor & ) {
88 werase( w_head );
90 _( "[%s] describe creatures, [%s] describe furniture, "
91 "[%s] describe terrain, [%s] close." ),
92 ctxt.get_desc( "CREATURE" ), ctxt.get_desc( "FURNITURE" ),
93 ctxt.get_desc( "TERRAIN" ), ctxt.get_desc( "QUIT" ) );
94
95 // Set up line drawings
96 for( int i = 0; i < TERMX; i++ ) {
97 mvwputch( w_head, point( i, top - 1 ), c_white, LINE_OXOX );
98 }
99
100 wnoutrefresh( w_head );
101
102 std::string desc;
103 // Allow looking at invisible tiles - player may want to examine hallucinations etc.
104 switch( cur_target ) {
106 const Creature *critter = seen_critter( *this, p );
107 if( critter != nullptr ) {
108 desc = critter->extended_description();
109 } else {
110 desc = _( "You do not see any creature here." );
111 }
112 }
113 break;
115 if( !u.sees( p ) || !m.has_furn( p ) ) {
116 desc = _( "You do not see any furniture here." );
117 } else {
118 const furn_id fid = m.furn( p );
119 if( display_mod_source ) {
120 const std::string mod_src = enumerate_as_string( fid->src.begin(),
121 fid->src.end(), []( const std::pair<furn_str_id, mod_id> &source ) {
122 return string_format( "'%s'", source.second->name() );
124 desc = string_format( _( "Origin: %s\n" ), mod_src );
125 }
126 if( display_object_ids ) {
127 desc += colorize( string_format( "[%s]\n", fid.id() ), c_light_blue );
128 }
129 desc += fid.obj().extended_description();
130 }
131 break;
133 if( !u.sees( p ) ) {
134 desc = _( "You can't see the terrain here." );
135 } else {
136 const ter_id tid = m.ter( p );
137 if( display_mod_source ) {
138 const std::string mod_src = enumerate_as_string( tid->src.begin(),
139 tid->src.end(), []( const std::pair<ter_str_id, mod_id> &source ) {
140 return string_format( "'%s'", source.second->name() );
142 desc = string_format( _( "Origin: %s\n" ), mod_src );
143 }
144 if( display_object_ids ) {
145 desc += colorize( string_format( "[%s]\n", tid.id() ), c_light_blue );
146 }
147 desc += tid.obj().extended_description();
148 }
149 break;
150 }
151
152 std::string signage = m.get_signage( p );
153 if( !signage.empty() ) {
154 // NOLINTNEXTLINE(cata-text-style): the question mark does not end a sentence
155 desc += u.has_trait( trait_ILLITERATE ) ? _( "\nSign: ???" ) : string_format( _( "\nSign: %s" ),
156 signage );
157 }
158
159 werase( w_main );
160 fold_and_print_from( w_main, point_zero, width, 0, c_light_gray, desc );
161 wnoutrefresh( w_main );
162 } );
163
164 do {
166 action = ctxt.handle_input();
167 if( action == "CREATURE" ) {
168 cur_target = description_target::creature;
169 } else if( action == "FURNITURE" ) {
171 } else if( action == "TERRAIN" ) {
172 cur_target = description_target::terrain;
173 }
174 } while( action != "CONFIRM" && action != "QUIT" );
175}
bool display_object_ids
Display internal IDs for items, furniture, terrain and monsters.
bool display_mod_source
Display mod source for items, furniture, terrain and monsters.
virtual std::string extended_description() const =0
const string_id< T > & id() const
Definition: ammo_effect.cpp:33
std::string get_signage(const tripoint &p) const
Definition: map.cpp:4120
std::string colorize(const std::string &text, const nc_color &color)
Definition: color.cpp:669
static const trait_id trait_ILLITERATE("ILLITERATE")
static const Creature * seen_critter(const game &g, const tripoint &p)
description_target
int fold_and_print_from(const catacurses::window &w, point begin, int width, int begin_line, const nc_color &base_color, const std::string &text)
Like fold_and_print, but starts the output with the N-th line of the folded string.
Definition: output.cpp:311
std::vector< std::pair< furn_str_id, mod_id > > src
Definition: mapdata.h:502
std::string extended_description() const
std::vector< std::pair< ter_str_id, mod_id > > src
Definition: mapdata.h:465

References _, action, arrow, c_light_blue, c_light_gray, c_white, colorize(), creature, display_mod_source, display_object_ids, enumerate_as_string(), map_data_common_t::extended_description(), Creature::extended_description(), fold_and_print_from(), map::furn(), furniture, input_context::get_desc(), get_map, map::get_signage(), input_context::handle_input(), map::has_furn(), Character::has_trait(), int_id< T >::id(), left, LINE_OXOX, m, mvwprintz(), mvwputch(), catacurses::newwin(), int_id< T >::obj(), point_zero, ui_manager::redraw(), input_context::register_action(), right, seen_critter(), Character::sees(), ter_t::src, furn_t::src, string_format(), map::ter(), TERMX, TERMY, terrain, trait_ILLITERATE, u, catacurses::werase(), and catacurses::wnoutrefresh().

Referenced by look_around().

◆ find_nearby_items()

std::vector< map_item_stack > game::find_nearby_items ( int  iRadius)
private

Definition at line 6951 of file game.cpp.

6952{
6953 std::map<std::string, map_item_stack> temp_items;
6954 std::vector<map_item_stack> ret;
6955 std::vector<std::string> item_order;
6956
6957 if( u.is_blind() ) {
6958 return ret;
6959 }
6960
6961 int range = fov_3d ? ( fov_3d_z_range * 2 ) + 1 : 1;
6962 int center_z = u.pos().z;
6963
6964 for( int i = 1; i <= range; i++ ) {
6965 int z = i % 2 ? center_z - i / 2 : center_z + i / 2;
6966 for( auto &points_p_it : closest_points_first( {u.pos().xy(), z}, iRadius ) ) {
6967 if( points_p_it.y >= u.posy() - iRadius && points_p_it.y <= u.posy() + iRadius &&
6968 u.sees( points_p_it ) &&
6969 m.sees_some_items( points_p_it, u ) ) {
6970
6971 for( auto &elem : m.i_at( points_p_it ) ) {
6972 const std::string name = elem.tname();
6973 const tripoint relative_pos = points_p_it - u.pos();
6974
6975 if( std::find( item_order.begin(), item_order.end(), name ) == item_order.end() ) {
6976 item_order.push_back( name );
6977 temp_items[name] = map_item_stack( &elem, relative_pos );
6978 } else {
6979 temp_items[name].add_at_pos( &elem, relative_pos );
6980 }
6981 }
6982 }
6983 }
6984 }
6985
6986 for( auto &elem : item_order ) {
6987 ret.push_back( temp_items[elem] );
6988 }
6989
6990 return ret;
6991}
int fov_3d_z_range
3D FoV range, in Z levels, in both directions.
bool fov_3d
3D FoV enabled/disabled.
@ range
Definition: character.h:104
bool is_blind() const
Returns true if the player isn't able to see.
Definition: character.cpp:6281
std::vector< coords::coord_point< Point, Origin, Scale > > closest_points_first(const coords::coord_point< Point, Origin, Scale > &loc, int min_dist, int max_dist)
Definition: coordinates.h:596

References closest_points_first(), detail::find(), fov_3d, fov_3d_z_range, map::i_at(), Character::is_blind(), m, om_direction::name(), Character::pos(), Character::posy(), range, cata::hash64_detail::ret, Character::sees(), map::sees_some_items(), u, and tripoint::z.

Referenced by list_items_monsters().

◆ find_npc()

npc * game::find_npc ( character_id  id)

Find the npc with the given ID.

Returns NULL if the npc could not be found. Searches all loaded overmaps.

Definition at line 1869 of file game.cpp.

1870{
1871 return overmap_buffer.find_npc( id ).get();
1872}

References overmapbuffer::find_npc(), and overmap_buffer.

Referenced by critter_by_id().

◆ find_or_make_stairs()

std::optional< tripoint > game::find_or_make_stairs ( map mp,
int  z_after,
bool &  rope_ladder,
bool  peeking 
)

Returns the other end of the stairs (if any).

May query, affect u etc.

Definition at line 10461 of file game.cpp.

10463{
10464 const int omtilesz = SEEX * 2;
10465 real_coords rc( m.getabs( point( u.posx(), u.posy() ) ) );
10466 tripoint omtile_align_start( m.getlocal( rc.begin_om_pos() ), z_after );
10467 tripoint omtile_align_end( omtile_align_start + point( -1 + omtilesz, -1 + omtilesz ) );
10468
10469 // Try to find the stairs.
10470 std::optional<tripoint> stairs;
10471 int best = INT_MAX;
10472 const int movez = z_after - get_levz();
10473 const bool going_down_1 = movez == -1;
10474 const bool going_up_1 = movez == 1;
10475 // If there are stairs on the same x and y as we currently are, use those
10476 if( going_down_1 && mp.has_flag( TFLAG_GOES_UP, u.pos() + tripoint_below ) ) {
10477 stairs.emplace( u.pos() + tripoint_below );
10478 }
10479 if( going_up_1 && mp.has_flag( TFLAG_GOES_DOWN, u.pos() + tripoint_above ) ) {
10480 stairs.emplace( u.pos() + tripoint_above );
10481 }
10482 // We did not find stairs directly above or below, so search the map for them
10483 if( !stairs.has_value() ) {
10484 for( const tripoint &dest : m.points_in_rectangle( omtile_align_start, omtile_align_end ) ) {
10485 if( rl_dist( u.pos(), dest ) <= best &&
10486 ( ( going_down_1 && mp.has_flag( TFLAG_GOES_UP, dest ) ) ||
10487 ( going_up_1 && ( mp.has_flag( TFLAG_GOES_DOWN, dest ) ||
10488 mp.ter( dest ) == t_manhole_cover ) ) ||
10489 ( ( movez == 2 || movez == -2 ) && mp.ter( dest ) == t_elevator ) ) ) {
10490 stairs.emplace( dest );
10491 best = rl_dist( u.pos(), dest );
10492 }
10493 }
10494 }
10495
10496 if( stairs.has_value() ) {
10497 if( Creature *blocking_creature = critter_at( stairs.value() ) ) {
10498 npc *guy = dynamic_cast<npc *>( blocking_creature );
10499 monster *mon = dynamic_cast<monster *>( blocking_creature );
10500 bool would_move = ( guy && !guy->is_enemy() ) || ( mon && mon->friendly == -1 );
10501 bool can_displace = find_empty_spot_nearby( *stairs ).has_value();
10502 std::string cr_name = blocking_creature->get_name();
10503 std::string msg;
10504 if( guy ) {
10505 //~ %s is the name of hostile NPC
10506 msg = string_format( _( "%s is in the way!" ), cr_name );
10507 } else {
10508 //~ %s is some monster
10509 msg = string_format( _( "There's a %s in the way!" ), cr_name );
10510 }
10511
10512 if( ( peeking && !would_move ) || !can_displace || ( !would_move && !query_yn(
10513 //~ %s is a warning about monster/hostile NPC in the way, e.g. "There's a zombie in the way!"
10514 _( "%s Attempt to push past? You may have to fight your way back up." ), msg ) ) ) {
10515 add_msg( msg );
10516 return std::nullopt;
10517 }
10518 }
10519 return stairs;
10520 }
10521
10522 // No stairs found! Try to make some
10523 rope_ladder = false;
10524 stairs.emplace( u.pos() );
10525 stairs->z = z_after;
10526 // Check the destination area for lava.
10527 if( mp.ter( *stairs ) == t_lava ) {
10528 if( movez < 0 &&
10529 !query_yn(
10530 _( "There is a LOT of heat coming out of there, even the stairs have melted away. Jump down? You won't be able to get back up." ) ) ) {
10531 return std::nullopt;
10532 } else if( movez > 0 &&
10533 !query_yn(
10534 _( "There is a LOT of heat coming out of there. Push through the half-molten rocks and ascend? You will not be able to get back down." ) ) ) {
10535 return std::nullopt;
10536 }
10537
10538 return stairs;
10539 }
10540
10541 if( movez > 0 ) {
10542 if( !mp.has_flag( "GOES_DOWN", *stairs ) ) {
10543 if( !query_yn( _( "You may be unable to return back down these stairs. Continue up?" ) ) ) {
10544 return std::nullopt;
10545 }
10546 }
10547 // Manhole covers need this to work
10548 // Maybe require manhole cover here and fail otherwise?
10549 return stairs;
10550 }
10551
10552 if( mp.impassable( *stairs ) ) {
10553 popup( _( "Halfway down, the way down becomes blocked off." ) );
10554 return std::nullopt;
10555 }
10556
10557 if( u.has_trait( trait_id( "WEB_RAPPEL" ) ) ) {
10558 if( query_yn( _( "There is a sheer drop halfway down. Web-descend?" ) ) ) {
10559 rope_ladder = true;
10560 if( ( rng( 4, 8 ) ) < u.get_skill_level( skill_dodge ) ) {
10561 add_msg( _( "You attach a web and dive down headfirst, flipping upright and landing on your feet." ) );
10562 } else {
10563 add_msg( _( "You securely web up and work your way down, lowering yourself safely." ) );
10564 }
10565 } else {
10566 return std::nullopt;
10567 }
10568 } else if( u.has_trait( trait_VINES2 ) || u.has_trait( trait_VINES3 ) ) {
10569 if( query_yn( _( "There is a sheer drop halfway down. Use your vines to descend?" ) ) ) {
10570 if( u.has_trait( trait_VINES2 ) ) {
10571 if( query_yn( _( "Detach a vine? It'll hurt, but you'll be able to climb back up…" ) ) ) {
10572 rope_ladder = true;
10573 add_msg( m_bad, _( "You descend on your vines, though leaving a part of you behind stings." ) );
10574 u.mod_pain( 5 );
10575 u.apply_damage( nullptr, bodypart_id( "torso" ), 5 );
10576 u.mod_stored_nutr( 10 );
10577 u.mod_thirst( 10 );
10578 } else {
10579 add_msg( _( "You gingerly descend using your vines." ) );
10580 }
10581 } else {
10582 add_msg( _( "You effortlessly lower yourself and leave a vine rooted for future use." ) );
10583 rope_ladder = true;
10584 u.mod_stored_nutr( 10 );
10585 u.mod_thirst( 10 );
10586 }
10587 } else {
10588 return std::nullopt;
10589 }
10590 } else if( u.has_amount( itype_grapnel, 1 ) ) {
10591 if( query_yn( _( "There is a sheer drop halfway down. Climb your grappling hook down?" ) ) ) {
10592 rope_ladder = true;
10594 } else {
10595 return std::nullopt;
10596 }
10597 } else if( u.has_amount( itype_rope_30, 1 ) ) {
10598 if( query_yn( _( "There is a sheer drop halfway down. Climb your rope down?" ) ) ) {
10599 rope_ladder = true;
10601 } else {
10602 return std::nullopt;
10603 }
10604 } else if( !query_yn( _( "There is a sheer drop halfway down. Jump?" ) ) ) {
10605 return std::nullopt;
10606 }
10607
10608 return stairs;
10609}
int_id< body_part_type > bodypart_id
Definition: bodypart.h:25
void mod_pain(int npain) override
Modifies a pain value by player traits before passing it to Creature::mod_pain()
Definition: character.cpp:764
void apply_damage(Creature *source, bodypart_id hurt, int dam, bool bypass_med=false) override
Actually hurt the player, hurts a body_part directly, no armor reduction.
Definition: character.cpp:8409
std::list< item > use_amount(itype_id it, int quantity, const std::function< bool(const item &)> &filter=return_true< item >)
Definition: character.cpp:9636
virtual void mod_thirst(int nthirst)
Definition: character.cpp:4439
virtual void mod_stored_nutr(int nnutr)
Definition: character.cpp:4329
int get_skill_level(const skill_id &ident) const
Definition: character.cpp:3350
tripoint getlocal(const tripoint &p) const
Inverse of getabs.
Definition: map.cpp:8417
bool impassable(const tripoint &p) const
Definition: map.cpp:1860
tripoint_range< tripoint > points_in_rectangle(const tripoint &from, const tripoint &to) const
Definition: map.cpp:8752
bool is_enemy() const
Definition: npc.cpp:2047
static const trait_id trait_VINES2("VINES2")
static const skill_id skill_dodge("dodge")
static std::optional< tripoint > find_empty_spot_nearby(const tripoint &pos)
Definition: game.cpp:9996
static const itype_id itype_rope_30("rope_30")
static const itype_id itype_grapnel("grapnel")
static const trait_id trait_VINES3("VINES3")
ter_id t_manhole_cover
Definition: mapdata.cpp:723
ter_id t_lava
Definition: mapdata.cpp:698
ter_id t_elevator
Definition: mapdata.cpp:726
@ TFLAG_GOES_DOWN
Definition: mapdata.h:309
@ TFLAG_GOES_UP
Definition: mapdata.h:310
auto dest(const elevator::tiles &elevator_here, const tripoint &sm_orig, int turns, int movez) -> elevator::tiles
static constexpr tripoint tripoint_below
Definition: point.h:281
static constexpr tripoint tripoint_above
Definition: point.h:280

References _, add_msg(), Character::apply_damage(), real_coords::begin_om_pos(), critter_at(), anonymous_namespace{iexamine_elevator.cpp}::elevator::dest(), find_empty_spot_nearby(), monster::friendly, get_levz(), Character::get_skill_level(), map::getabs(), map::getlocal(), visitable< T >::has_amount(), map::has_flag(), Character::has_trait(), map::impassable(), npc::is_enemy(), itype_grapnel, itype_rope_30, m, m_bad, Character::mod_pain(), Character::mod_stored_nutr(), Character::mod_thirst(), map::points_in_rectangle(), popup(), Character::pos(), Character::posx(), Character::posy(), query_yn(), rl_dist(), rng(), SEEX, skill_dodge, string_format(), t_elevator, t_lava, t_manhole_cover, map::ter(), TFLAG_GOES_DOWN, TFLAG_GOES_UP, trait_VINES2, trait_VINES3, tripoint_above, tripoint_below, u, and Character::use_amount().

Referenced by vertical_move().

◆ fling_creature()

void game::fling_creature ( Creature c,
const units::angle dir,
float  flvel,
bool  controlled = false 
)

Flings the input creature in the given direction.

Definition at line 9799 of file game.cpp.

9800{
9801 if( c == nullptr ) {
9802 debugmsg( "game::fling_creature invoked on null target" );
9803 return;
9804 }
9805
9806 if( c->is_dead_state() ) {
9807 // Flinging a corpse causes problems, don't enable without testing
9808 return;
9809 }
9810
9811 if( c->is_hallucination() ) {
9812 // Don't fling hallucinations
9813 return;
9814 }
9815
9816 bool thru = true;
9817 const bool is_u = ( c == &u );
9818 // Don't animate critters getting bashed if animations are off
9819 const bool animate = is_u || get_option<bool>( "ANIMATIONS" );
9820
9821 player *p = dynamic_cast<player *>( c );
9822
9823 tileray tdir( dir );
9824 int range = flvel / 10;
9825 tripoint pt = c->pos();
9826 tripoint prev_point = pt;
9827 bool force_next = false;
9828 tripoint next_forced;
9829 while( range > 0 ) {
9830 c->set_underwater( false );
9831 // TODO: Check whenever it is actually in the viewport
9832 // or maybe even just redraw the changed tiles
9833 bool seen = is_u || u.sees( *c ); // To avoid redrawing when not seen
9834 if( force_next ) {
9835 pt = next_forced;
9836 force_next = false;
9837 } else {
9838 tdir.advance();
9839 pt.x = c->posx() + tdir.dx();
9840 pt.y = c->posy() + tdir.dy();
9841 }
9842 float force = 0;
9843
9844 if( m.obstructed_by_vehicle_rotation( prev_point, pt ) ) {
9845 //We process the intervening tile on this iteration and then the current tile on the next
9846 next_forced = pt;
9847 force_next = true;
9848 if( one_in( 2 ) ) {
9849 pt.x = prev_point.x;
9850 } else {
9851 pt.y = prev_point.y;
9852 }
9853 }
9854
9855
9856 if( monster *const mon_ptr = critter_at<monster>( pt ) ) {
9857 monster &critter = *mon_ptr;
9858 // Approximate critter's "stopping power" with its max hp
9859 force = std::min<float>( 1.5f * critter.type->hp, flvel );
9860 const int damage = rng( force, force * 2.0f ) / 6;
9861 c->impact( damage, pt );
9862 // Multiply zed damage by 6 because no body parts
9863 const int zed_damage = std::max( 0,
9864 ( damage - critter.get_armor_bash( bodypart_id( "torso" ) ) ) * 6 );
9865 // TODO: Pass the "flinger" here - it's not the flung critter that deals damage
9866 critter.apply_damage( c, bodypart_id( "torso" ), zed_damage );
9867 critter.check_dead_state();
9868 if( !critter.is_dead() ) {
9869 thru = false;
9870 }
9871 } else if( m.impassable( pt ) ) {
9872 if( !m.veh_at( pt ).obstacle_at_part() ) {
9873 force = std::min<float>( m.bash_strength( pt ), flvel );
9874 } else {
9875 // No good way of limiting force here
9876 // Keep it 1 less than maximum to make the impact hurt
9877 // but to keep the target flying after it
9878 force = flvel - 1;
9879 }
9880 const int damage = rng( force, force * 2.0f ) / 9;
9881 c->impact( damage, pt );
9882 if( m.is_bashable( pt ) ) {
9883 // Only go through if we successfully make the tile passable
9884 m.bash( pt, flvel );
9885 thru = m.passable( pt );
9886 } else {
9887 thru = false;
9888 }
9889 }
9890
9891 // If the critter dies during flinging, moving it around causes debugmsgs
9892 if( c->is_dead_state() ) {
9893 return;
9894 }
9895
9896 flvel -= force;
9897 if( thru ) {
9898 if( p != nullptr ) {
9899 if( p->in_vehicle ) {
9900 m.unboard_vehicle( p->pos() );
9901 }
9902 // If we're flinging the player around, make sure the map stays centered on them.
9903 if( is_u ) {
9904 update_map( pt.x, pt.y );
9905 } else {
9906 p->setpos( pt );
9907 }
9908 } else if( !critter_at( pt ) ) {
9909 // Dying monster doesn't always leave an empty tile (blob spawning etc.)
9910 // Just don't setpos if it happens - next iteration will do so
9911 // or the monster will stop a tile before the unpassable one
9912 c->setpos( pt );
9913 }
9914 } else {
9915 // Don't zero flvel - count this as slamming both the obstacle and the ground
9916 // although at lower velocity
9917 break;
9918 }
9919 //Vehicle wall tiles don't count for range
9920 if( !force_next ) {
9921 range--;
9922 }
9923 prev_point = pt;
9924 if( animate && ( seen || u.sees( *c ) ) ) {
9929 }
9930 }
9931
9932 // Fall down to the ground - always on the last reached tile
9933 if( !m.has_flag( "SWIMMABLE", c->pos() ) ) {
9934 const trap_id trap_under_creature = m.tr_at( c->pos() ).loadid;
9935 // Didn't smash into a wall or a floor so only take the fall damage
9936 if( thru && trap_under_creature == tr_ledge ) {
9937 m.creature_on_trap( *c, false );
9938 } else {
9939 // Fall on ground
9940 int force = rng( flvel, flvel * 2 ) / 9;
9941 if( controlled ) {
9942 force = std::max( force / 2 - 5, 0 );
9943 }
9944 if( force > 0 ) {
9945 int dmg = c->impact( force, c->pos() );
9946 // TODO: Make landing damage the floor
9947 m.bash( c->pos(), dmg / 4, false, false, false );
9948 }
9949 // Always apply traps to creature i.e. bear traps, tele traps etc.
9950 m.creature_on_trap( *c, false );
9951 }
9952 } else {
9953 c->set_underwater( true );
9954 if( is_u ) {
9955 if( controlled ) {
9956 add_msg( _( "You dive into water." ) );
9957 } else {
9958 add_msg( m_warning, _( "You fall into water." ) );
9959 }
9960 }
9961 }
9962}
void setpos(const tripoint &p) override
Definition: character.h:813
void check_dead_state()
This function checks the creatures is_dead_state and (if true) calls die.
Definition: creature.cpp:1899
point update_map(player &p)
Definition: game.cpp:10688
void pump_events()
Resize & refresh if necessary, process all pending window events, and ignore keypresses.
int bash_strength(const tripoint &p, bool allow_floor=false) const
Returns max_str of the furniture or terrain at p.
Definition: map.cpp:2543
bool obstructed_by_vehicle_rotation(const tripoint &from, const tripoint &to) const
Checks if a rotated vehicle is blocking diagonal movement, tripoints must be adjacent.
Definition: map.cpp:6623
bash_results bash(const tripoint &p, int str, bool silent=false, bool destroy=false, bool bash_floor=false, const vehicle *bashing_vehicle=nullptr)
Returns a pair where first is whether anything was smashed and second is if it was destroyed.
Definition: map.cpp:3624
void unboard_vehicle(const vpart_reference &, Character *passenger, bool dead_passenger=false)
Definition: map.cpp:1146
bool is_bashable(const tripoint &p, bool allow_floor=false) const
Returns true if there is a bashable vehicle part or the furn/terrain is bashable at p.
Definition: map.cpp:2507
void creature_on_trap(Creature &critter, bool may_avoid=true)
Apply trap effects to the creature, similar to creature_in_field.
Definition: map.cpp:8629
bool passable(const tripoint &p) const
Definition: map.cpp:1865
int get_armor_bash(bodypart_id bp) const override
Definition: monster.cpp:1909
bool is_dead() const
Definition: monster.cpp:2819
void apply_damage(Creature *source, bodypart_id bp, int dam, bool bypass_med=false) override
Definition: monster.cpp:1690
std::optional< vpart_reference > obstacle_at_part() const
Definition: vehicle.cpp:2495
Definition: player.h:84
static const trap_str_id tr_ledge("tr_ledge")
void redraw_invalidated()
Redraw all invalidated windows without invalidating the top window.
Definition: ui_manager.cpp:394
int hp
Definition: mtype.h:271
trap_id loadid
Definition: trap.h:88
int y
Definition: point.h:137
int x
Definition: point.h:136

References _, add_msg(), tileray::advance(), monster::apply_damage(), map::bash(), map::bash_strength(), c, Creature::check_dead_state(), map::creature_on_trap(), critter_at(), debugmsg, tileray::dx(), tileray::dy(), monster::get_armor_bash(), map::has_flag(), mtype::hp, map::impassable(), Character::in_vehicle, inp_mngr, invalidate_main_ui_adaptor(), map::is_bashable(), monster::is_dead(), trap::loadid, m, m_warning, optional_vpart_position::obstacle_at_part(), map::obstructed_by_vehicle_rotation(), one_in(), map::passable(), Character::pos(), input_manager::pump_events(), range, ui_manager::redraw_invalidated(), refresh_display(), rng(), Character::sees(), Character::setpos(), map::tr_at(), tr_ledge, monster::type, u, map::unboard_vehicle(), update_map(), map::veh_at(), tripoint::x, and tripoint::y.

Referenced by moving_vehicle_dismount().

◆ forced_door_closing()

bool game::forced_door_closing ( const tripoint p,
const ter_id door_type,
int  bash_dmg 
)

Definition at line 5014 of file game.cpp.

5015{
5016 const auto valid_location = [&]( const tripoint & p ) {
5017 return g->is_empty( p );
5018 };
5019 const auto get_random_point = [&]() -> tripoint {
5020 if( auto pos = random_point( m.points_in_radius( p, 2 ), valid_location ) )
5021 {
5022 return p * 2 - ( *pos );
5023 } else
5024 {
5025 return p;
5026 }
5027 };
5028
5029 const std::string &door_name = door_type.obj().name();
5030 const tripoint kbp = get_random_point();
5031
5032 // can't pushback any creatures/items anywhere, that means the door can't close.
5033 const bool cannot_push = kbp == p;
5034 const bool can_see = u.sees( p );
5035
5036 player *npc_or_player = critter_at<player>( p, false );
5037 if( npc_or_player != nullptr ) {
5038 if( bash_dmg <= 0 ) {
5039 return false;
5040 }
5041 if( npc_or_player->is_npc() && can_see ) {
5042 add_msg( _( "The %1$s hits the %2$s." ), door_name, npc_or_player->name );
5043 } else if( npc_or_player->is_player() ) {
5044 add_msg( m_bad, _( "The %s hits you." ), door_name );
5045 }
5046 if( npc_or_player->activity ) {
5047 npc_or_player->cancel_activity();
5048 }
5049 // TODO: make the npc angry?
5050 npc_or_player->hitall( bash_dmg, 0, nullptr );
5051 if( cannot_push ) {
5052 return false;
5053 }
5054 // TODO implement who was closing the door and replace nullptr
5055 knockback( kbp, p, std::max( 1, bash_dmg / 10 ), -1, 1, nullptr );
5056 // TODO: perhaps damage/destroy the gate
5057 // if the npc was really big?
5058 }
5059 if( monster *const mon_ptr = critter_at<monster>( p ) ) {
5060 monster &critter = *mon_ptr;
5061 if( bash_dmg <= 0 ) {
5062 return false;
5063 }
5064 if( can_see ) {
5065 add_msg( _( "The %1$s hits the %2$s." ), door_name, critter.name() );
5066 }
5067 if( critter.type->size <= MS_SMALL ) {
5068 critter.die_in_explosion( nullptr );
5069 } else {
5070 critter.apply_damage( nullptr, bodypart_id( "torso" ), bash_dmg );
5071 critter.check_dead_state();
5072 }
5073 if( !critter.is_dead() && critter.type->size >= MS_HUGE ) {
5074 // big critters simply prevent the gate from closing
5075 // TODO: perhaps damage/destroy the gate
5076 // if the critter was really big?
5077 return false;
5078 }
5079 if( !critter.is_dead() ) {
5080 // Still alive? Move the critter away so the door can close
5081 if( cannot_push ) {
5082 return false;
5083 }
5084 // TODO implement who was closing the door and replace nullptr
5085 knockback( kbp, p, std::max( 1, bash_dmg / 10 ), -1, 1, nullptr );
5086 if( critter_at( p ) ) {
5087 return false;
5088 }
5089 }
5090 }
5091 if( const optional_vpart_position vp = m.veh_at( p ) ) {
5092 if( bash_dmg <= 0 ) {
5093 return false;
5094 }
5095 vp->vehicle().damage( vp->part_index(), bash_dmg );
5096 if( m.veh_at( p ) ) {
5097 // Check again in case all parts at the door tile
5098 // have been destroyed, if there is still a vehicle
5099 // there, the door can not be closed
5100 return false;
5101 }
5102 }
5103 if( bash_dmg < 0 && !m.i_at( p ).empty() ) {
5104 return false;
5105 }
5106 if( bash_dmg == 0 ) {
5107 for( auto &elem : m.i_at( p ) ) {
5108 if( elem.made_of( LIQUID ) ) {
5109 // Liquids are OK, will be destroyed later
5110 continue;
5111 } else if( elem.volume() < 250_ml ) {
5112 // Dito for small items, will be moved away
5113 continue;
5114 }
5115 // Everything else prevents the door from closing
5116 return false;
5117 }
5118 }
5119
5120 m.ter_set( p, door_type );
5121 if( m.has_flag( "NOITEM", p ) ) {
5122 map_stack items = m.i_at( p );
5123 for( map_stack::iterator it = items.begin(); it != items.end(); ) {
5124 if( it->made_of( LIQUID ) ) {
5125 it = items.erase( it );
5126 continue;
5127 }
5128 if( it->made_of( material_id( "glass" ) ) && one_in( 2 ) ) {
5129 if( can_see ) {
5130 add_msg( m_warning, _( "A %s shatters!" ), it->tname() );
5131 } else {
5132 add_msg( m_warning, _( "Something shatters!" ) );
5133 }
5134 it = items.erase( it );
5135 continue;
5136 }
5137 if( cannot_push ) {
5138 return false;
5139 }
5140 m.add_item_or_charges( kbp, *it );
5141 it = items.erase( it );
5142 }
5143 }
5144 return true;
5145}
int hitall(int dam, int vary, Creature *source)
Harms all body parts for dam, with armor reduction.
Definition: character.cpp:8686
void knockback(const tripoint &s, const tripoint &t, int force, int stun, int dam_mult, Creature *source)
Definition: game.cpp:4253
iterator erase(const_iterator it) override
Definition: map.cpp:154
bool ter_set(const tripoint &p, const ter_id &new_terrain)
Definition: map.cpp:1704
void die_in_explosion(Creature *source)
Definition: monster.cpp:1704
bool is_npc() const override
Definition: player.h:103
bool is_player() const override
Definition: player.h:93
@ MS_SMALL
Definition: creature.h:59
@ MS_HUGE
Definition: creature.h:62
@ LIQUID
Definition: enums.h:175
std::optional< tripoint > random_point(const map &m, const std::function< bool(const tripoint &)> &predicate)
Same as other random_point with a range enclosing all valid points of the map.
std::string name() const
Definition: mapdata.cpp:514
m_size size
Definition: mtype.h:263

References _, Character::activity, map::add_item_or_charges(), add_msg(), monster::apply_damage(), item_stack::begin(), Character::cancel_activity(), Creature::check_dead_state(), critter_at(), monster::die_in_explosion(), item_stack::empty(), item_stack::end(), map_stack::erase(), g, map::has_flag(), Character::hitall(), map::i_at(), monster::is_dead(), player::is_npc(), player::is_player(), knockback(), LIQUID, m, m_bad, m_warning, MS_HUGE, MS_SMALL, Character::name, map_data_common_t::name(), monster::name(), int_id< T >::obj(), one_in(), map::points_in_radius(), random_point(), Character::sees(), mtype::size, map::ter_set(), monster::type, u, and map::veh_at().

◆ gametype()

special_game_type game::gametype ( ) const

Definition at line 539 of file game.cpp.

540{
542}

References gamemode, and NONE.

◆ get_creature_if()

Creature * game::get_creature_if ( const std::function< bool(const Creature &)> &  pred)

Returns a creature matching a predicate.

Only living (not dead) creatures are checked. Returns nullptr if no creature matches the predicate. There is no guarantee which creature is returned when several creatures match.

Definition at line 12051 of file game.cpp.

12052{
12053 for( Creature &critter : all_creatures() ) {
12054 if( pred( critter ) ) {
12055 return &critter;
12056 }
12057 }
12058 return nullptr;
12059}

References all_creatures().

◆ get_creatures_if()

std::vector< Creature * > game::get_creatures_if ( const std::function< bool(const Creature &)> &  pred)

Returns all creatures matching a predicate.

Only living ( not dead ) creatures are checked ( and returned ). Returned pointers are never null.

Definition at line 11961 of file game.cpp.

11963{
11964 std::vector<Creature *> result;
11965 for( Creature &critter : all_creatures() ) {
11966 if( pred( critter ) ) {
11967 result.push_back( &critter );
11968 }
11969 }
11970 return result;
11971}

References all_creatures().

◆ get_cur_om()

overmap & game::get_cur_om ( ) const

The overmap which contains the center submap of the reality bubble.

Definition at line 11941 of file game.cpp.

11942{
11943 // The player is located in the middle submap of the map.
11945 const tripoint pos_om = sm_to_om_copy( sm );
11946 // TODO: fix point types
11947 return overmap_buffer.get( point_abs_om( pos_om.xy() ) );
11948}
tripoint get_abs_sub() const
return abs_sub
Definition: map.cpp:8433
overmap & get(const point_abs_om &)
Uses overmap coordinates, that means x and y are directly compared with the position of the overmap.
point sm_to_om_copy(point p)
coords::coord_point< point, coords::origin::abs, coords::om > point_abs_om
Definition: coordinates.h:483
static constexpr int HALF_MAPSIZE
constexpr scale sm
Definition: coordinates.h:31

References overmapbuffer::get(), map::get_abs_sub(), HALF_MAPSIZE, m, overmap_buffer, coords::sm, sm_to_om_copy(), and tripoint::xy().

Referenced by start_game().

◆ get_dangerous_tile()

std::vector< std::string > game::get_dangerous_tile ( const tripoint dest_loc) const

Definition at line 8747 of file game.cpp.

8748{
8749 std::vector<std::string> harmful_stuff;
8750 const auto fields_here = m.field_at( u.pos() );
8751 for( const auto &e : m.field_at( dest_loc ) ) {
8752 // warn before moving into a dangerous field except when already standing within a similar field
8753 if( u.is_dangerous_field( e.second ) && fields_here.find_field( e.first ) == nullptr ) {
8754 harmful_stuff.push_back( e.second.name() );
8755 }
8756 }
8757
8758 if( !u.is_blind() ) {
8759 const trap &tr = m.tr_at( dest_loc );
8760 const bool boardable = static_cast<bool>( m.veh_at( dest_loc ).part_with_feature( "BOARDABLE",
8761 true ) );
8762 // HACK: Hack for now, later ledge should stop being a trap
8763 // Note: in non-z-level mode, ledges obey different rules and so should be handled as regular traps
8764 if( tr.loadid == tr_ledge && m.has_zlevels() ) {
8765 if( !boardable ) {
8766 harmful_stuff.emplace_back( tr.name() );
8767 }
8768 } else if( tr.can_see( dest_loc, u ) && !tr.is_benign() && !boardable ) {
8769 harmful_stuff.emplace_back( tr.name() );
8770 }
8771
8772 static const std::set< body_part > sharp_bps = {
8775 };
8776
8777 const auto sharp_bp_check = [this]( body_part bp ) {
8778 return character_funcs::is_bp_immune_to( u, bp, { DT_CUT, 10 } );
8779 };
8780
8781 if( m.has_flag( "ROUGH", dest_loc ) && !m.has_flag( "ROUGH", u.pos() ) && !boardable &&
8782 ( u.get_armor_bash( bodypart_id( "foot_l" ) ) < 5 ||
8783 u.get_armor_bash( bodypart_id( "foot_r" ) ) < 5 ) ) {
8784 harmful_stuff.emplace_back( m.name( dest_loc ) );
8785 } else if( m.has_flag( "SHARP", dest_loc ) && !m.has_flag( "SHARP", u.pos() ) && !( u.in_vehicle ||
8786 m.veh_at( dest_loc ) ) &&
8787 u.dex_cur < 78 && !std::all_of( sharp_bps.begin(), sharp_bps.end(), sharp_bp_check ) ) {
8788 harmful_stuff.emplace_back( m.name( dest_loc ) );
8789 }
8790
8791 }
8792
8793 return harmful_stuff;
8794}
@ bp_foot_l
Definition: bodypart.h:52
@ bp_leg_r
Definition: bodypart.h:51
@ bp_eyes
Definition: bodypart.h:44
@ bp_hand_l
Definition: bodypart.h:48
@ bp_arm_l
Definition: bodypart.h:46
@ bp_leg_l
Definition: bodypart.h:50
@ bp_hand_r
Definition: bodypart.h:49
@ bp_head
Definition: bodypart.h:43
@ bp_torso
Definition: bodypart.h:42
@ bp_mouth
Definition: bodypart.h:45
@ bp_foot_r
Definition: bodypart.h:53
@ bp_arm_r
Definition: bodypart.h:47
int dex_cur
Definition: character.h:265
int get_armor_bash(bodypart_id bp) const override
Returns overall bashing resistance for the body_part.
Definition: character.cpp:6870
bool is_dangerous_field(const field_entry &entry) const
Returns true if the given field entry is dangerous to us.
Definition: creature.cpp:199
const field & field_at(const tripoint &p) const
Get the fields that are here.
Definition: map.cpp:5420
bool has_zlevels() const
Definition: map.h:1640
@ DT_CUT
Definition: damage.h:25
bool is_bp_immune_to(const Character &who, body_part bp, damage_unit dam)
Check if character's body part is immune to given damage.
Definition: trap.h:86
std::string name() const
Definition: trap.cpp:177
bool can_see(const tripoint &pos, const Character &p) const
Can player/npc p see this kind of trap, either by their memory (they known there is the trap) or by t...
Definition: trap.cpp:223
bool is_benign() const
If true, this is not really a trap and there won't be any safety queries before stepping onto it (e....
Definition: trap.h:159

References bp_arm_l, bp_arm_r, bp_eyes, bp_foot_l, bp_foot_r, bp_hand_l, bp_hand_r, bp_head, bp_leg_l, bp_leg_r, bp_mouth, bp_torso, trap::can_see(), Character::dex_cur, DT_CUT, map::field_at(), Character::get_armor_bash(), map::has_flag(), map::has_zlevels(), Character::in_vehicle, trap::is_benign(), Character::is_blind(), character_funcs::is_bp_immune_to(), Creature::is_dangerous_field(), trap::loadid, m, trap::name(), map::name(), optional_vpart_position::part_with_feature(), Character::pos(), map::tr_at(), tr_ledge, u, and map::veh_at().

Referenced by is_dangerous_tile(), prompt_dangerous_tile(), and walk_move().

◆ get_fishable_locations()

std::unordered_set< tripoint > game::get_fishable_locations ( int  distance,
const tripoint fish_pos 
)

Get the contiguous fishable locations starting at fish_pos, out to the specificed distance.

Parameters
distanceDistance around the fish_pos to examine for contiguous fishable locations.
fish_posThe location being fished.
Returns
A set of locations representing the valid contiguous fishable locations.

Definition at line 3611 of file game.cpp.

3612{
3613 // We're going to get the contiguous fishable terrain starting at
3614 // the provided fishing location (e.g. where a line was cast or a fish
3615 // trap was set), and then check whether or not fishable monsters are
3616 // actually in those locations. This will help us ensure that we're
3617 // getting our fish from the location that we're ACTUALLY fishing,
3618 // rather than just somewhere in the vicinity.
3619
3620 std::unordered_set<tripoint> visited;
3621
3622 const tripoint fishing_boundary_min( fish_pos + point( -distance, -distance ) );
3623 const tripoint fishing_boundary_max( fish_pos + point( distance, distance ) );
3624
3625 const inclusive_cuboid<tripoint> fishing_boundaries(
3626 fishing_boundary_min, fishing_boundary_max );
3627
3628 const auto get_fishable_terrain = [&]( tripoint starting_point,
3629 std::unordered_set<tripoint> &fishable_terrain ) {
3630 std::queue<tripoint> to_check;
3631 to_check.push( starting_point );
3632 while( !to_check.empty() ) {
3633 const tripoint current_point = to_check.front();
3634 to_check.pop();
3635
3636 // We've been here before, so bail.
3637 if( visited.find( current_point ) != visited.end() ) {
3638 continue;
3639 }
3640
3641 // This point is out of bounds, so bail.
3642 if( !fishing_boundaries.contains( current_point ) ) {
3643 continue;
3644 }
3645
3646 // Mark this point as visited.
3647 visited.emplace( current_point );
3648
3649 if( m.has_flag( "FISHABLE", current_point ) ) {
3650 fishable_terrain.emplace( current_point );
3651 to_check.push( current_point + point_south );
3652 to_check.push( current_point + point_north );
3653 to_check.push( current_point + point_east );
3654 to_check.push( current_point + point_west );
3655 }
3656 }
3657 return;
3658 };
3659
3660 // Starting at the provided location, get our fishable terrain
3661 // and populate a set with those locations which we'll then use
3662 // to determine if any fishable monsters are in those locations.
3663 std::unordered_set<tripoint> fishable_points;
3664 get_fishable_terrain( fish_pos, fishable_points );
3665
3666 return fishable_points;
3667}
static constexpr point point_west
Definition: point.h:268
static constexpr point point_south
Definition: point.h:266
static constexpr point point_north
Definition: point.h:262
static constexpr point point_east
Definition: point.h:264

References inclusive_cuboid< Tripoint, >::contains(), map::has_flag(), m, point_east, point_north, point_south, and point_west.

◆ get_fishable_monsters()

std::vector< monster * > game::get_fishable_monsters ( std::unordered_set< tripoint > &  fishable_locations)

Get the fishable monsters within the provided fishable locations.

Parameters
fishable_locationsA set of locations which are valid fishable terrain. Any fishable monsters are filtered by this collection to determine those which can actually be caught.
Returns
Fishable monsters within the specified fishable terrain.

Definition at line 3669 of file game.cpp.

3671{
3672 std::vector<monster *> unique_fish;
3673 for( monster &critter : all_monsters() ) {
3674 // If it is fishable...
3675 if( critter.has_flag( MF_FISHABLE ) ) {
3676 const tripoint critter_pos = critter.pos();
3677 // ...and it is in a fishable location.
3678 if( fishable_locations.find( critter_pos ) != fishable_locations.end() ) {
3679 unique_fish.push_back( &critter );
3680 }
3681 }
3682 }
3683
3684 return unique_fish;
3685}
@ MF_FISHABLE
Definition: mtype.h:143

References all_monsters(), and MF_FISHABLE.

◆ get_follower_list()

std::set< character_id > game::get_follower_list ( )

Get set of followers.

Definition at line 1966 of file game.cpp.

1967{
1968 return follower_ids;
1969}

References follower_ids.

◆ get_kill_tracker()

kill_tracker & game::get_kill_tracker ( )

Definition at line 2723 of file game.cpp.

2724{
2725 return *kill_tracker_ptr;
2726}

References kill_tracker_ptr.

Referenced by cleanup_at_end(), death_screen(), handle_action(), setup(), and win().

◆ get_levx()

int game::get_levx ( ) const

The top left corner of the reality bubble (in submaps coordinates).

This is the same as map::abs_sub of the m map.

Definition at line 11926 of file game.cpp.

11927{
11928 return m.get_abs_sub().x;
11929}

References map::get_abs_sub(), m, and tripoint::x.

Referenced by create_starting_npcs(), load_npcs(), look_around(), save_cyborg(), spawn_hallucination(), vertical_move(), and vertical_shift().

◆ get_levy()

int game::get_levy ( ) const

Definition at line 11931 of file game.cpp.

11932{
11933 return m.get_abs_sub().y;
11934}

References map::get_abs_sub(), m, and tripoint::y.

Referenced by create_starting_npcs(), load_npcs(), look_around(), save_cyborg(), spawn_hallucination(), vertical_move(), and vertical_shift().

◆ get_levz()

◆ get_moves_since_last_save()

int game::get_moves_since_last_save ( ) const

Definition at line 7127 of file game.cpp.

7128{
7129 return moves_since_last_save;
7130}

References moves_since_last_save.

◆ get_npcs_if()

std::vector< npc * > game::get_npcs_if ( const std::function< bool(const npc &)> &  pred)

Definition at line 11973 of file game.cpp.

11974{
11975 std::vector<npc *> result;
11976 for( npc &guy : all_npcs() ) {
11977 if( pred( guy ) ) {
11978 result.push_back( &guy );
11979 }
11980 }
11981 return result;
11982}

References all_npcs().

Referenced by allies(), chat(), and validate_npc_followers().

◆ get_player_base_save_path()

std::string game::get_player_base_save_path ( ) const

Base path for saving player data.

Just add a suffix (unique for the thing you want to save) and use the resulting path. Example: save_ui_data(get_player_base_save_path()+".ui")

Definition at line 12061 of file game.cpp.

12062{
12063 return get_world_base_save_path() + "/" + base64_encode( get_avatar().get_save_id() );
12064}
std::string base64_encode(const std::string &str)
std::string get_world_base_save_path() const
Base path for saving world data.
Definition: game.cpp:12066
friend avatar & get_avatar()
Definition: avatar.cpp:105

References base64_encode(), get_avatar, and get_world_base_save_path().

Referenced by save_player_data().

◆ get_player_input()

input_context game::get_player_input ( std::string &  action)
private

Definition at line 247 of file handle_action.cpp.

248{
249 input_context ctxt;
250 if( uquit == QUIT_WATCH ) {
251 ctxt = input_context( "DEFAULTMODE" );
252 ctxt.set_iso( true );
253 // The list of allowed actions in death-cam mode in game::handle_action
254 // *INDENT-OFF*
255 for( const action_id id : {
268 } ) {
269 ctxt.register_action( action_ident( id ) );
270 }
271 // *INDENT-ON*
272 ctxt.register_action( "QUIT", to_translation( "Accept your fate" ) );
273 } else {
275 }
276
278
279 user_turn current_turn;
280
281
282 // Checking early if we will need to handle animations
283 // If we do not need to handle animations that will not change as long as the user has not selected an action
284 // and we can handle it like we are not animating.
285 weather_printable wPrint;
286 bool animate_weather = false;
287 bool animate_sct = false;
288 bool do_animations = [&]() {
289 if( get_option<bool>( "ANIMATIONS" ) ) {
290 const bool weather_has_anim = init_weather_anim( get_weather().weather_id, wPrint );
291
292 animate_weather = weather_has_anim && get_option<bool>( "ANIMATION_RAIN" );
293 animate_sct = !SCT.vSCT.empty() && uquit != QUIT_WATCH && get_option<bool>( "ANIMATION_SCT" );
294
295#if defined(TILES)
296 // Always animate, minimap and terrain may have animations to run
297 return true;
298#else
299 // Otherwise we need to see if we actually should animate.
300 // Minimap and Terrain never animate in !TILES
301 return animate_weather || animate_sct || uquit == QUIT_WATCH;
302#endif
303 }
304 return false;
305 }
306 ();
307
308 if( do_animations ) {
309 ctxt.set_timeout( 125 );
310
312 make_shared_fast<game::draw_callback_t>( [&]() {
313 if( animate_weather ) {
314 draw_weather( wPrint );
315 }
316 if( animate_sct ) {
317 draw_sct();
318 }
319 } );
320 add_draw_callback( animation_cb );
321 invalidate_main_ui_adaptor(); // We want to redraw at least once.
322
323 do {
324 if( animate_weather ) {
326 generate_weather_anim_frame( get_weather().weather_id, wPrint );
327 }
328 // don't bother calculating SCT if we won't show it
329 if( animate_sct ) {
331
333
334 //Check for creatures on all drawing positions and offset if necessary
335 for( auto iter = SCT.vSCT.rbegin(); iter != SCT.vSCT.rend(); ++iter ) {
336 const direction oCurDir = iter->getDirecton();
337 const int width = utf8_width( iter->getText() );
338 for( int i = 0; i < width; ++i ) {
339 tripoint tmp( iter->getPosX() + i, iter->getPosY(), get_levz() );
340 const Creature *critter = critter_at( tmp, true );
341
342 if( critter != nullptr && u.sees( *critter ) ) {
343 i = -1;
344 int iPos = iter->getStep() + iter->getStepOffset();
345 for( auto iter2 = iter; iter2 != SCT.vSCT.rend(); ++iter2 ) {
346 if( iter2->getDirecton() == oCurDir &&
347 iter2->getStep() + iter2->getStepOffset() <= iPos ) {
348 if( iter2->getType() == "hp" ) {
349 iter2->advanceStepOffset();
350 }
351
352 iter2->advanceStepOffset();
353 iPos = iter2->getStep() + iter2->getStepOffset();
354 }
355 }
356 }
357 }
358 }
359
360 // Stop animation when done
361 animate_sct = !SCT.vSCT.empty();
362 }
363 // We don't cache these checks as their result may change after 1st redraw
365 // TODO: we redraw *everything* just to animate a couple blinking dots
366 // on the minimap or a few tiles.
367 // This is far from ideal, and can probably be done much cheaper
368 // (update only part of the screen? draw static parts into a texture?)
370 }
371
372 std::unique_ptr<static_popup> deathcam_msg_popup;
373 if( uquit == QUIT_WATCH ) {
374 deathcam_msg_popup = std::make_unique<static_popup>();
375 deathcam_msg_popup
376 ->wait_message( c_red, _( "Press %s to accept your fate…" ), ctxt.get_desc( "QUIT" ) )
377 .on_top( true );
378 }
379
381 } while( handle_mouseview( ctxt, action ) && uquit != QUIT_WATCH
382 && ( action != "TIMEOUT" || !current_turn.has_timeout_elapsed() ) );
383 ctxt.reset_timeout();
384 } else {
387 SCT.vSCT.clear();
388
389 ctxt.set_timeout( 125 );
390 while( handle_mouseview( ctxt, action ) ) {
391 if( action == "TIMEOUT" && current_turn.has_timeout_elapsed() ) {
392 break;
393 }
394 }
395 ctxt.reset_timeout();
396 }
397
398 return ctxt;
399}
std::string action_ident(action_id act)
Lookup a unique string identifier for a given action ID.
Definition: action.cpp:70
action_id
Enumerates all discrete actions that can be performed by player.
Definition: action.h:18
@ ACTION_CENTER
Center the viewport on character.
Definition: action.h:73
@ ACTION_SHIFT_SW
Move viewport south-west.
Definition: action.h:85
@ ACTION_SHIFT_NW
Move viewport north-west.
Definition: action.h:89
@ ACTION_KEYBINDINGS
Display keybindings list.
Definition: action.h:255
@ ACTION_SHIFT_E
Move viewport east.
Definition: action.h:79
@ ACTION_TOGGLE_MAP_MEMORY
Toggle memorized tiles being shown.
Definition: action.h:71
@ ACTION_SHIFT_S
Move viewport south.
Definition: action.h:83
@ ACTION_SHIFT_SE
Move viewport south-east.
Definition: action.h:81
@ ACTION_LOOK
Toggle look mode.
Definition: action.h:115
@ ACTION_SHIFT_NE
Move viewport north-east.
Definition: action.h:77
@ ACTION_SHIFT_W
Move viewport west.
Definition: action.h:87
@ ACTION_SHIFT_N
Move viewport north.
Definition: action.h:75
bool terrain_requires_animation()
Definition: animation.cpp:1204
bool minimap_requires_animation()
Definition: animation.cpp:1195
void draw_sct()
Definition: animation.cpp:865
void draw_weather(const weather_printable &wPrint)
Definition: animation.cpp:824
void add_draw_callback(shared_ptr_fast< draw_callback_t > cb)
Definition: game.cpp:3024
bool handle_mouseview(input_context &ctxt, std::string &action)
Definition: game.cpp:1997
void set_timeout(int val)
Sets input polling timeout as appropriate for the current interface system.
Definition: input.cpp:1452
std::string get_desc(const std::string &action_descriptor, unsigned int max_limit=0, const input_event_filter &evt_filter=allow_all_keys) const
Get a description text for the key/other input method associated with the given action.
Definition: input.cpp:750
void register_action(const std::string &action_descriptor)
Register an action with this input context.
Definition: input.cpp:672
void set_iso(bool mode=true)
Definition: input.cpp:1423
void reset_timeout()
Definition: input.cpp:1457
std::vector< cSCT > vSCT
Definition: output.h:916
void advanceAllSteps()
Definition: output.cpp:1924
bool has_timeout_elapsed()
input_context get_default_mode_input_context()
Definition: game.cpp:2097
static bool init_weather_anim(const weather_type_id &wtype, weather_printable &wPrint)
static void generate_weather_anim_frame(const weather_type_id &wtype, weather_printable &wPrint)
direction
Definition: line.h:39
scrollingcombattext SCT
Definition: output.cpp:65
Weather drawing tracking.
Definition: weather.h:59
translation to_translation(const std::string &raw)
Shorthands for translation::to_translation.

References _, action, ACTION_CENTER, action_ident(), ACTION_KEYBINDINGS, ACTION_LOOK, ACTION_SHIFT_E, ACTION_SHIFT_N, ACTION_SHIFT_NE, ACTION_SHIFT_NW, ACTION_SHIFT_S, ACTION_SHIFT_SE, ACTION_SHIFT_SW, ACTION_SHIFT_W, ACTION_TOGGLE_MAP_MEMORY, add_draw_callback(), scrollingcombattext::advanceAllSteps(), c_red, critter_at(), draw_sct(), draw_weather(), generate_weather_anim_frame(), get_default_mode_input_context(), input_context::get_desc(), get_levz(), get_weather, handle_mouseview(), user_turn::has_timeout_elapsed(), init_weather_anim(), invalidate_main_ui_adaptor(), m, minimap_requires_animation(), Character::posz(), QUIT_WATCH, ui_manager::redraw_invalidated(), input_context::register_action(), input_context::reset_timeout(), SCT, Character::sees(), input_context::set_iso(), input_context::set_timeout(), terrain_requires_animation(), to_translation(), u, map::update_visibility_cache(), uquit, utf8_width(), and scrollingcombattext::vSCT.

Referenced by handle_action().

◆ get_seed()

unsigned int game::get_seed ( ) const

Definition at line 1778 of file game.cpp.

1779{
1780 return seed;
1781}

References seed.

◆ get_user_action_counter()

int game::get_user_action_counter ( ) const

Definition at line 7132 of file game.cpp.

7133{
7134 return user_action_counter;
7135}

References user_action_counter.

◆ get_veh_dir_indicator_location()

std::optional< tripoint > game::get_veh_dir_indicator_location ( bool  next) const

Returns the location where the indicator should go relative to the reality bubble, or nothing to indicate no indicator should be drawn.

Based on the vehicle the player is driving, if any.

Parameters
nextIf true, bases it on the vehicle the vehicle will turn to next turn, instead of the one it is currently facing.

Definition at line 3279 of file game.cpp.

3280{
3281 if( !get_option<bool>( "VEHICLE_DIR_INDICATOR" ) ) {
3282 return std::nullopt;
3283 }
3284 const optional_vpart_position vp = m.veh_at( u.pos() );
3285 if( !vp ) {
3286 return std::nullopt;
3287 }
3288 vehicle *const veh = &vp->vehicle();
3289 rl_vec2d face = next ? veh->dir_vec() : veh->face_vec();
3290 float r = 10.0;
3291 return tripoint( static_cast<int>( r * face.x ), static_cast<int>( r * face.y ), u.pos().z );
3292}
rl_vec2d dir_vec() const

References vehicle::dir_vec(), vehicle::face_vec(), m, Character::pos(), u, map::veh_at(), rl_vec2d::x, rl_vec2d::y, and tripoint::z.

Referenced by draw_veh_dir_indicator().

◆ get_world_base_save_path()

std::string game::get_world_base_save_path ( ) const

Base path for saving world data.

This yields a path to a folder.

Definition at line 12066 of file game.cpp.

12067{
12068 if( world_generator->active_world == nullptr ) {
12069 return PATH_INFO::savedir();
12070 }
12071 return world_generator->active_world->folder_path();
12072}
std::string savedir()
Definition: path_info.cpp:246

References PATH_INFO::savedir(), and world_generator.

Referenced by get_player_base_save_path(), load(), load_master(), move_save_to_graveyard(), save_artifacts(), save_factions_missions_npcs(), and setup().

◆ get_zoom()

int game::get_zoom ( ) const

Definition at line 7118 of file game.cpp.

7119{
7120#if defined(TILES)
7121 return tileset_zoom;
7122#else
7123 return DEFAULT_TILESET_ZOOM;
7124#endif
7125}

References DEFAULT_TILESET_ZOOM, and tileset_zoom.

Referenced by look_around().

◆ grabbed_furn_move()

bool game::grabbed_furn_move ( const tripoint dp)
private
Strength determines ability to drag furniture

Definition at line 9552 of file game.cpp.

9553{
9554 // Furniture: pull, push, or standing still and nudging object around.
9555 // Can push furniture out of reach.
9556 tripoint fpos = u.pos() + u.grab_point;
9557 // supposed position of grabbed furniture
9558 if( !m.has_furn( fpos ) ) {
9559 // Where did it go? We're grabbing thin air so reset.
9560 add_msg( m_info, _( "No furniture at grabbed point." ) );
9561 u.grab( OBJECT_NONE );
9562 return false;
9563 }
9564
9565 const bool pushing_furniture = dp == u.grab_point;
9566 const bool pulling_furniture = dp == -u.grab_point;
9567 const bool shifting_furniture = !pushing_furniture && !pulling_furniture;
9568
9569 tripoint fdest = fpos + dp; // intended destination of furniture.
9570 // Check floor: floorless tiles don't need to be flat and have no traps
9571 const bool has_floor = m.has_floor( fdest );
9572 // Unfortunately, game::is_empty fails for tiles we're standing on,
9573 // which will forbid pulling, so:
9574 const bool canmove = (
9575 m.passable( fdest ) &&
9576 critter_at<npc>( fdest ) == nullptr &&
9577 critter_at<monster>( fdest ) == nullptr &&
9578 ( !pulling_furniture || is_empty( u.pos() + dp ) ) &&
9579 ( !has_floor || m.has_flag( "FLAT", fdest ) ) &&
9580 !m.has_furn( fdest ) &&
9581 !m.veh_at( fdest ) &&
9582 ( !has_floor || m.tr_at( fdest ).is_null() )
9583 );
9584
9585 const furn_t furntype = m.furn( fpos ).obj();
9586 const int src_items = m.i_at( fpos ).size();
9587 const int dst_items = m.i_at( fdest ).size();
9588
9589 const bool only_liquid_items = std::all_of( m.i_at( fdest ).begin(), m.i_at( fdest ).end(),
9590 [&]( item & liquid_item ) {
9591 return liquid_item.made_of( LIQUID );
9592 } );
9593
9594 const bool dst_item_ok = !m.has_flag( "NOITEM", fdest ) &&
9595 !m.has_flag( "SWIMMABLE", fdest ) &&
9596 !m.has_flag( "DESTROY_ITEM", fdest );
9597
9598 const bool src_item_ok = m.furn( fpos ).obj().has_flag( "CONTAINER" ) ||
9599 m.furn( fpos ).obj().has_flag( "FIRE_CONTAINER" ) ||
9600 m.furn( fpos ).obj().has_flag( "SEALED" );
9601
9602 const int fire_intensity = m.get_field_intensity( fpos, fd_fire );
9603 time_duration fire_age = m.get_field_age( fpos, fd_fire );
9604
9605 int str_req = furntype.move_str_req;
9606 // Factor in weight of items contained in the furniture.
9607 units::mass furniture_contents_weight = 0_gram;
9608 for( auto &contained_item : m.i_at( fpos ) ) {
9609 furniture_contents_weight += contained_item.weight();
9610 }
9611 str_req += furniture_contents_weight / 4_kilogram;
9612 int adjusted_str = u.get_str();
9613 if( u.is_mounted() ) {
9614 auto mons = u.mounted_creature.get();
9615 if( mons->has_flag( MF_RIDEABLE_MECH ) && mons->mech_str_addition() != 0 ) {
9616 adjusted_str = mons->mech_str_addition();
9617 }
9618 }
9619 if( !canmove ) {
9620 // TODO: What is something?
9621 add_msg( _( "The %s collides with something." ), furntype.name() );
9622 u.moves -= 50;
9623 return true;
9624 ///\EFFECT_STR determines ability to drag furniture
9625 } else if( str_req > adjusted_str &&
9626 one_in( std::max( 20 - str_req - adjusted_str, 2 ) ) ) {
9627 add_msg( m_bad, _( "You strain yourself trying to move the heavy %s!" ),
9628 furntype.name() );
9629 u.moves -= 100;
9630 u.mod_pain( 1 ); // Hurt ourselves.
9631 return true; // furniture and or obstacle wins.
9632 } else if( !src_item_ok && !only_liquid_items && dst_items > 0 ) {
9633 add_msg( _( "There's stuff in the way." ) );
9634 u.moves -= 50;
9635 return true;
9636 }
9637
9638 u.moves -= str_req * 10;
9639 // Additional penalty if we can't comfortably move it.
9640 if( str_req > adjusted_str ) {
9641 int move_penalty = std::pow( str_req, 2.0 ) + 100.0;
9642 if( move_penalty <= 1000 ) {
9643 if( adjusted_str >= str_req - 3 ) {
9644 u.moves -= std::max( 3000, move_penalty * 10 );
9645 add_msg( m_bad, _( "The %s is really heavy!" ), furntype.name() );
9646 if( one_in( 3 ) ) {
9647 add_msg( m_bad, _( "You fail to move the %s." ), furntype.name() );
9648 return true;
9649 }
9650 } else {
9651 u.moves -= 100;
9652 add_msg( m_bad, _( "The %s is too heavy for you to budge." ), furntype.name() );
9653 return true;
9654 }
9655 }
9656 u.moves -= move_penalty;
9657 if( move_penalty > 500 ) {
9658 add_msg( _( "Moving the heavy %s is taking a lot of time!" ),
9659 furntype.name() );
9660 } else if( move_penalty > 200 ) {
9661 if( one_in( 3 ) ) { // Nag only occasionally.
9662 add_msg( _( "It takes some time to move the heavy %s." ),
9663 furntype.name() );
9664 }
9665 }
9666 }
9668 _( "a scraping noise." ), true, "misc", "scraping" );
9669
9671 ( tripoint_abs_ms( m.getabs( fpos ) ) );
9672
9673 // Actually move the furniture.
9674 m.furn_set( fdest, m.furn( fpos ), atd ? atd->clone() : nullptr );
9675 m.furn_set( fpos, f_null );
9676
9677 if( fire_intensity == 1 && !pulling_furniture ) {
9678 m.remove_field( fpos, fd_fire );
9679 m.set_field_intensity( fdest, fd_fire, fire_intensity );
9680 m.set_field_age( fdest, fd_fire, fire_age );
9681 }
9682
9683 // Is there is only liquids on the ground, remove them after moving furniture.
9684 if( dst_items > 0 && only_liquid_items ) {
9685 m.i_clear( fdest );
9686 }
9687
9688 if( src_items > 0 ) { // Move the stuff inside.
9689 if( dst_item_ok && src_item_ok ) {
9690 // Assume contents of both cells are legal, so we can just swap contents.
9691 std::list<item> temp;
9692 std::move( m.i_at( fpos ).begin(), m.i_at( fpos ).end(),
9693 std::back_inserter( temp ) );
9694 m.i_clear( fpos );
9695 for( auto item_iter = m.i_at( fdest ).begin();
9696 item_iter != m.i_at( fdest ).end(); ++item_iter ) {
9697 m.i_at( fpos ).insert( *item_iter );
9698 }
9699 m.i_clear( fdest );
9700 for( auto &cur_item : temp ) {
9701 m.i_at( fdest ).insert( cur_item );
9702 }
9703 } else {
9704 add_msg( _( "Stuff spills from the %s!" ), furntype.name() );
9705 }
9706 }
9707
9708 if( shifting_furniture ) {
9709 // We didn't move
9710 tripoint d_sum = u.grab_point + dp;
9711 if( std::abs( d_sum.x ) < 2 && std::abs( d_sum.y ) < 2 ) {
9712 u.grab_point = d_sum; // furniture moved relative to us
9713 } else { // we pushed furniture out of reach
9714 add_msg( _( "You let go of the %s." ), furntype.name() );
9715 u.grab( OBJECT_NONE );
9716 }
9717 return true; // We moved furniture but stayed still.
9718 }
9719
9720 if( pushing_furniture && m.impassable( fpos ) ) {
9721 // Not sure how that chair got into a wall, but don't let player follow.
9722 add_msg( _( "You let go of the %1$s as it slides past %2$s." ),
9723 furntype.name(), m.tername( fdest ) );
9724 u.grab( OBJECT_NONE );
9725 return true;
9726 }
9727
9728 return false;
9729}
virtual int get_str() const
Getters for stats exclusive to characters.
Definition: character.cpp:4089
virtual active_tile_data * clone() const =0
void grab(object_type grab_type, const tripoint &grab_point=tripoint_zero)
Definition: avatar.cpp:665
bool is_empty(const tripoint &p)
Returns true if there is no player, NPC, or monster on the tile and move_cost > 0.
Definition: game.cpp:4848
void insert(const item &newitem) override
Definition: map.cpp:159
void remove_field(const tripoint &p, const field_type_id &field_to_remove)
Remove field entry at xy, ignored if the field entry is not present.
Definition: map.cpp:5593
time_duration set_field_age(const tripoint &p, const field_type_id &type, const time_duration &age, bool isoffset=false)
Set age of field entry at point.
Definition: map.cpp:5460
time_duration get_field_age(const tripoint &p, const field_type_id &type) const
Get the age of a field entry (field_entry::age), if there is no field of that type,...
Definition: map.cpp:5494
int get_field_intensity(const tripoint &p, const field_type_id &type) const
Get the intensity of a field entry (field_entry::intensity), if there is no field of that type,...
Definition: map.cpp:5500
int set_field_intensity(const tripoint &p, const field_type_id &type, int new_intensity, bool isoffset=false)
Set intensity of field entry at point, creating if not present, removing if intensity becomes 0.
Definition: map.cpp:5473
std::string tername(const tripoint &p) const
Definition: map.cpp:1774
void i_clear(const tripoint &p)
Definition: map.cpp:4248
void furn_set(const tripoint &p, const furn_id &new_furniture, cata::poly_serialized< active_tile_data > new_active=nullptr)
Sets the furniture at given position.
Definition: map.cpp:1425
bool has_floor(const tripoint &p) const
Definition: map.cpp:2072
tripoint grab_point
Definition: player.h:235
@ OBJECT_NONE
Definition: enums.h:187
field_type_id fd_fire
Definition: field_type.cpp:345
furn_id f_null
Definition: mapdata.cpp:1098
template active_tile_data * furn_at< active_tile_data >(const tripoint_abs_ms &)
bool move(avatar &you, map &m, const tripoint &d)
void sound(const tripoint &p, int vol, sound_t category, const std::string &description, bool ambient=false, const std::string &id="", const std::string &variant="default")
Sound at (p) of intensity (vol)
Definition: sounds.cpp:178
int move_str_req
Definition: mapdata.h:519
bool has_flag(const std::string &flag) const
Definition: mapdata.h:421

References _, add_msg(), item_stack::begin(), active_tile_data::clone(), item_stack::end(), f_null, fd_fire, map::furn(), active_tiles::furn_at< active_tile_data >(), map::furn_set(), map::get_field_age(), map::get_field_intensity(), Character::get_str(), map::getabs(), avatar::grab(), player::grab_point, map_data_common_t::has_flag(), map::has_flag(), map::has_floor(), map::has_furn(), map::i_at(), map::i_clear(), map::impassable(), map_stack::insert(), is_empty(), Character::is_mounted(), trap::is_null(), m, m_bad, m_info, MF_RIDEABLE_MECH, Character::mod_pain(), Character::mounted_creature, avatar_action::move(), furn_t::move_str_req, sounds::movement, Creature::moves, map_data_common_t::name(), int_id< T >::obj(), OBJECT_NONE, one_in(), map::passable(), Character::pos(), map::remove_field(), map::set_field_age(), map::set_field_intensity(), item_stack::size(), sounds::sound(), map::tername(), map::tr_at(), u, map::veh_at(), tripoint::x, and tripoint::y.

Referenced by grabbed_move().

◆ grabbed_move()

bool game::grabbed_move ( const tripoint dp)
private

Check for dangerous stuff at dest_loc, return false if the player decides not to step there.

Definition at line 9731 of file game.cpp.

9732{
9733 if( u.get_grab_type() == OBJECT_NONE ) {
9734 return false;
9735 }
9736
9737 if( dp.z != 0 ) {
9738 // No dragging stuff up/down stairs yet!
9739 return false;
9740 }
9741
9742 // vehicle: pulling, pushing, or moving around the grabbed object.
9743 if( u.get_grab_type() == OBJECT_VEHICLE ) {
9744 return grabbed_veh_move( dp );
9745 }
9746
9747 if( u.get_grab_type() == OBJECT_FURNITURE ) {
9748 return grabbed_furn_move( dp );
9749 }
9750
9751 add_msg( m_info, _( "Nothing at grabbed point %d,%d,%d or bad grabbed object type." ),
9753 u.grab( OBJECT_NONE );
9754 return false;
9755}
object_type get_grab_type() const
Definition: avatar.cpp:673
bool grabbed_furn_move(const tripoint &dp)
Definition: game.cpp:9552
bool grabbed_veh_move(const tripoint &dp)
Definition: grab.cpp:95
@ OBJECT_FURNITURE
Definition: enums.h:197
@ OBJECT_VEHICLE
Definition: enums.h:193

References _, add_msg(), avatar::get_grab_type(), avatar::grab(), player::grab_point, grabbed_furn_move(), grabbed_veh_move(), m_info, OBJECT_FURNITURE, OBJECT_NONE, OBJECT_VEHICLE, u, tripoint::x, tripoint::y, and tripoint::z.

Referenced by walk_move().

◆ grabbed_veh_move()

bool game::grabbed_veh_move ( const tripoint dp)
private
Strength determines ability to drag vehicles Strength increases speed of dragging vehicles Strength decreases stamina cost of dragging vehicles

Definition at line 95 of file grab.cpp.

96{
97 const optional_vpart_position grabbed_vehicle_vp = m.veh_at( u.pos() + u.grab_point );
98 if( !grabbed_vehicle_vp ) {
99 add_msg( m_info, _( "No vehicle at grabbed point." ) );
100 u.grab( OBJECT_NONE );
101 return false;
102 }
103 vehicle *grabbed_vehicle = &grabbed_vehicle_vp->vehicle();
104 if( !grabbed_vehicle ||
105 !grabbed_vehicle->handle_potential_theft( u ) ) {
106 return false;
107 }
108 const int grabbed_part = grabbed_vehicle_vp->part_index();
109 for( int part_index = 0; part_index < grabbed_vehicle->part_count(); ++part_index ) {
110 monster *mon = grabbed_vehicle->get_pet( part_index );
111 if( mon != nullptr && mon->has_effect( effect_harnessed ) ) {
112 add_msg( m_info, _( "You cannot move this vehicle whilst your %s is harnessed!" ),
113 mon->get_name() );
114 u.grab( OBJECT_NONE );
115 return false;
116 }
117 }
118 const vehicle *veh_under_player = veh_pointer_or_null( m.veh_at( u.pos() ) );
119 if( grabbed_vehicle == veh_under_player ) {
120 u.grab_point = -dp;
121 return false;
122 }
123
124 tripoint dp_veh = -u.grab_point;
125 const tripoint prev_grab = u.grab_point;
126 tripoint next_grab = u.grab_point;
127
128 bool zigzag = false;
129
130 if( dp == prev_grab ) {
131 // We are pushing in the direction of vehicle
132 dp_veh = dp;
133 } else if( std::abs( dp.x + dp_veh.x ) != 2 && std::abs( dp.y + dp_veh.y ) != 2 ) {
134 // Not actually moving the vehicle, don't do the checks
135 u.grab_point = -( dp + dp_veh );
136 return false;
137 } else if( ( dp.x == prev_grab.x || dp.y == prev_grab.y ) &&
138 next_grab.x != 0 && next_grab.y != 0 ) {
139 // Zig-zag (or semi-zig-zag) pull: player is diagonal to vehicle
140 // and moves away from it, but not directly away
141 dp_veh.x = dp.x == -dp_veh.x ? 0 : dp_veh.x;
142 dp_veh.y = dp.y == -dp_veh.y ? 0 : dp_veh.y;
143
144 next_grab = -dp_veh;
145 zigzag = true;
146 } else {
147 // We are pulling the vehicle
148 next_grab = -dp;
149 }
150
151 // Make sure the mass and pivot point are correct
152 grabbed_vehicle->invalidate_mass();
153
154 //vehicle movement: strength check. very strong humans can move about 2,000 kg in a wheelbarrow.
155 // int str_req = grabbed_vehicle->total_mass() / 100_kilogram; //strength required to move vehicle.
156 // for smaller vehicles, offroad_str_req_cap sanity-checks our results.
157 int str_req = std::min( get_vehicle_str_requirement( grabbed_vehicle ),
158 offroad_str_req_cap( grabbed_vehicle ) );
159 int str = u.get_str();
160 if( u.is_mounted() ) {
161 auto mons = u.mounted_creature.get();
162 if( mons->has_flag( MF_RIDEABLE_MECH ) && mons->mech_str_addition() != 0 ) {
163 str = mons->mech_str_addition();
164 }
165 }
166 add_msg( m_debug, "str_req: %d", str_req );
167
168 //final strength check and outcomes
169 ///\EFFECT_STR determines ability to drag vehicles
170 if( str_req <= str ) {
171 if( !grabbed_vehicle->valid_wheel_config() ) {
172 make_scraping_noise( grabbed_vehicle->global_pos3(), str_req * 2 );
173 }
174
175 //calculate exertion factor and movement penalty
176 ///\EFFECT_STR increases speed of dragging vehicles
177 u.moves -= 400 * str_req / std::max( 1, str );
178 ///\EFFECT_STR decreases stamina cost of dragging vehicles
179 u.mod_stamina( -200 * str_req / std::max( 1, str ) );
180 const int ex = dice( 1, 6 ) - 1 + str_req;
181 if( ex > str + 1 ) {
182 // Pain and movement penalty if exertion exceeds character strength
183 add_msg( m_bad, _( "You strain yourself to move the %s!" ), grabbed_vehicle->name );
184 u.moves -= 200;
185 u.mod_pain( 1 );
186 } else if( ex >= str ) {
187 // Movement is slow if exertion nearly equals character strength
188 add_msg( _( "It takes some time to move the %s." ), grabbed_vehicle->name );
189 u.moves -= 200;
190 }
191 } else {
192 u.moves -= 100;
193 add_msg( m_bad, _( "You lack the strength to move the %s" ), grabbed_vehicle->name );
194 return true;
195 }
196
197 std::string blocker_name = _( "errors in movement code" );
198 const auto get_move_dir = [&]( const tripoint & dir, const tripoint & from ) {
199 tileray mdir;
200
201 mdir.init( dir.xy() );
202 grabbed_vehicle->turn( mdir.dir() - grabbed_vehicle->face.dir() );
203 grabbed_vehicle->face = grabbed_vehicle->turn_dir;
204 grabbed_vehicle->precalc_mounts( 1, mdir.dir(), grabbed_vehicle->pivot_point() );
205
206 // Grabbed part has to stay at distance 1 to the player
207 // and in roughly the same direction.
208 const tripoint new_part_pos = grabbed_vehicle->global_pos3() +
209 grabbed_vehicle->part( grabbed_part ).precalc[ 1 ];
210 const tripoint expected_pos = u.pos() + dp + from;
211 const tripoint actual_dir = expected_pos - new_part_pos;
212
213 grabbed_vehicle->adjust_zlevel( 1, dp );
214
215 // Set player location to illegal value so it can't collide with vehicle.
216 const tripoint player_prev = u.pos();
218 std::vector<veh_collision> colls;
219 const bool failed = grabbed_vehicle->collision( colls, actual_dir, true );
220 u.setpos( player_prev );
221 if( !colls.empty() ) {
222 blocker_name = colls.front().target_name;
223 }
224 return failed ? tripoint_zero : actual_dir;
225 };
226
227 // First try the move as intended
228 // But if that fails and the move is a zig-zag, try to recover:
229 // Try to place the vehicle in the position player just left rather than "flattening" the zig-zag
230 tripoint final_dp_veh = get_move_dir( dp_veh, next_grab );
231 if( final_dp_veh == tripoint_zero && zigzag ) {
232 final_dp_veh = get_move_dir( -prev_grab, -dp );
233 next_grab = -dp;
234 }
235
236 if( final_dp_veh == tripoint_zero ) {
237 add_msg( _( "The %s collides with %s." ), grabbed_vehicle->name, blocker_name );
238 u.grab_point = prev_grab;
239 return true;
240 }
241
242 u.grab_point = next_grab;
243
244 m.displace_vehicle( *grabbed_vehicle, final_dp_veh );
245
246 if( grabbed_vehicle ) {
247 grabbed_vehicle->shift_zlevel();
248 grabbed_vehicle->check_falling_or_floating();
249 } else {
250 debugmsg( "Grabbed vehicle disappeared" );
251 return false;
252 }
253
254 for( int p : grabbed_vehicle->wheelcache ) {
255 if( one_in( 2 ) ) {
256 tripoint wheel_p = grabbed_vehicle->global_part_pos3( grabbed_part );
257 grabbed_vehicle->handle_trap( wheel_p, p );
258 }
259 }
260
261 return false;
262
263}
void mod_stamina(int mod)
Definition: character.cpp:7114
bool displace_vehicle(vehicle &veh, const tripoint &dp)
Definition: map.cpp:1184
void init(point ad)
Definition: tileray.cpp:27
units::angle dir() const
Definition: tileray.cpp:74
void turn(units::angle deg)
void adjust_zlevel(int idir=0, const tripoint &offset=tripoint_zero)
tripoint global_pos3() const
Definition: vehicle.cpp:3283
bool valid_wheel_config() const
Definition: vehicle.cpp:4482
std::vector< int > wheelcache
Definition: vehicle.h:1550
void check_falling_or_floating()
point pivot_point() const
Definition: vehicle.cpp:5849
tileray face
Definition: vehicle.h:1680
void invalidate_mass()
Mark mass caches and pivot cache as dirty.
Definition: vehicle.cpp:6993
int part_count() const
Definition: vehicle.cpp:7100
bool collision(std::vector< veh_collision > &colls, const tripoint &dp, bool just_detect, bool bash_floor=false)
void precalc_mounts(int idir, units::angle dir, point pivot)
Definition: vehicle.cpp:3152
monster * get_pet(int p) const
Definition: vehicle.cpp:3264
vehicle_part & part(int part_num)
Definition: vehicle.cpp:7105
void handle_trap(const tripoint &p, int part)
tripoint global_part_pos3(const int &index) const
Get the coordinates of the studied part of the vehicle.
Definition: vehicle.cpp:3288
void shift_zlevel()
units::angle turn_dir
Definition: vehicle.h:1659
static const efftype_id effect_harnessed("harnessed")
auto offroad_str_req_cap(vehicle *veh) -> int
Definition: grab.cpp:42
auto get_vehicle_str_requirement(vehicle *veh) -> int
Definition: grab.cpp:78
auto make_scraping_noise(const tripoint &pos, const int volume) -> void
Definition: grab.cpp:29
static constexpr tripoint tripoint_zero
Definition: point.h:259
int dice(int number, int sides)
Definition: rng.cpp:85
std::array< tripoint, 2 > precalc
mount translated to face.dir [0] and turn_dir [1]
Definition: vehicle_part.h:210

References _, add_msg(), vehicle::adjust_zlevel(), vehicle::check_falling_or_floating(), vehicle::collision(), debugmsg, dice(), tileray::dir(), map::displace_vehicle(), effect_harnessed, vehicle::face, failed, monster::get_name(), vehicle::get_pet(), Character::get_str(), anonymous_namespace{grab.cpp}::get_vehicle_str_requirement(), vehicle::global_part_pos3(), vehicle::global_pos3(), avatar::grab(), player::grab_point, vehicle::handle_potential_theft(), vehicle::handle_trap(), Creature::has_effect(), tileray::init(), vehicle::invalidate_mass(), Character::is_mounted(), m, m_bad, m_debug, m_info, anonymous_namespace{grab.cpp}::make_scraping_noise(), MF_RIDEABLE_MECH, Character::mod_pain(), Character::mod_stamina(), Character::mounted_creature, Creature::moves, vehicle::name, OBJECT_NONE, anonymous_namespace{grab.cpp}::offroad_str_req_cap(), one_in(), vehicle::part(), vehicle::part_count(), vehicle::pivot_point(), Character::pos(), vehicle_part::precalc, vehicle::precalc_mounts(), Character::setpos(), vehicle::shift_zlevel(), tripoint_zero, vehicle::turn(), vehicle::turn_dir, u, vehicle::valid_wheel_config(), map::veh_at(), veh_pointer_or_null(), vehicle::wheelcache, tripoint::x, tripoint::xy(), and tripoint::y.

Referenced by grabbed_move().

◆ handle_action()

bool game::handle_action ( )
private

Definition at line 1529 of file handle_action.cpp.

1530{
1531 std::string action;
1532 input_context ctxt;
1534 user_turn current_turn;
1535 // Check if we have an auto-move destination
1536 if( u.has_destination() ) {
1538 if( act == ACTION_NULL ) {
1539 add_msg( m_info, _( "Auto-move canceled" ) );
1541 return false;
1542 }
1543 } else if( u.has_destination_activity() ) {
1544 // starts destination activity after the player successfully reached his destination
1546 return false;
1547 } else {
1548 // No auto-move, ask player for input
1549 ctxt = get_player_input( action );
1550 }
1551
1552 const optional_vpart_position vp = m.veh_at( u.pos() );
1553 bool veh_ctrl = !u.is_dead_state() &&
1554 ( ( vp && vp->vehicle().player_in_control( u ) ) || remoteveh() != nullptr );
1555
1556 // If performing an action with right mouse button, co-ordinates
1557 // of location clicked.
1558 std::optional<tripoint> mouse_target;
1559
1560 if( uquit == QUIT_WATCH && action == "QUIT" ) {
1561 uquit = QUIT_DIED;
1562 return false;
1563 }
1564
1565 if( act == ACTION_NULL ) {
1567
1568 if( act == ACTION_KEYBINDINGS ) {
1569 // already handled by input context
1570 return false;
1571 }
1572
1573 if( act == ACTION_MAIN_MENU ) {
1574 if( uquit == QUIT_WATCH ) {
1575 return false;
1576 }
1577 // No auto-move actions have or can be set at this point.
1579 destination_preview.clear();
1581 if( act == ACTION_NULL ) {
1582 return false;
1583 }
1584 }
1585
1586 if( act == ACTION_ACTIONMENU ) {
1587 if( uquit == QUIT_WATCH ) {
1588 return false;
1589 }
1590 // No auto-move actions have or can be set at this point.
1592 destination_preview.clear();
1594 if( act == ACTION_NULL ) {
1595 return false;
1596 }
1597#if defined(__ANDROID__)
1598 if( get_option<bool>( "ANDROID_ACTIONMENU_AUTOADD" ) && ctxt.get_category() == "DEFAULTMODE" ) {
1599 add_best_key_for_action_to_quick_shortcuts( act, ctxt.get_category(), false );
1600 }
1601#endif
1602 }
1603
1604 if( act == ACTION_KEYBINDINGS ) {
1606 destination_preview.clear();
1607 act = ctxt.display_menu( true );
1608 if( act == ACTION_NULL ) {
1609 return false;
1610 }
1611 }
1612
1615 }
1616
1617 if( act == ACTION_SELECT || act == ACTION_SEC_SELECT ) {
1618 // Mouse button click
1619 if( veh_ctrl ) {
1620 // No mouse use in vehicle
1621 return false;
1622 }
1623
1624 if( u.is_dead_state() ) {
1625 // do not allow mouse actions while dead
1626 return false;
1627 }
1628
1629 const std::optional<tripoint> mouse_pos = ctxt.get_coordinates( w_terrain );
1630 if( !mouse_pos ) {
1631 return false;
1632 } else if( !u.sees( *mouse_pos ) ) {
1633 // Not clicked in visible terrain
1634 return false;
1635 }
1636 mouse_target = mouse_pos;
1637
1638 if( act == ACTION_SELECT ) {
1639 // Note: The following has the potential side effect of
1640 // setting auto-move destination state in addition to setting
1641 // act.
1642 if( !try_get_left_click_action( act, *mouse_target ) ) {
1643 return false;
1644 }
1645 } else if( act == ACTION_SEC_SELECT ) {
1646 if( !try_get_right_click_action( act, *mouse_target ) ) {
1647 return false;
1648 }
1649 }
1650 } else if( act != ACTION_TIMEOUT ) {
1651 // act has not been set for an auto-move, so clearing possible
1652 // auto-move destinations. Since initializing an auto-move with
1653 // the mouse may span across multiple actions, we do not clear the
1654 // auto-move destination if the action is only a timeout, as this
1655 // would require the user to double click quicker than the
1656 // timeout delay.
1658 destination_preview.clear();
1659 }
1660 }
1661
1662 if( act == ACTION_NULL ) {
1663 const input_event &&evt = ctxt.get_raw_input();
1664 if( !evt.sequence.empty() ) {
1665 const int ch = evt.get_first_input();
1666 const std::string &&name = inp_mngr.get_keyname( ch, evt.type, true );
1667 if( !get_option<bool>( "NO_UNKNOWN_COMMAND_MSG" ) ) {
1668 add_msg( m_info, _( "Unknown command: \"%s\" (%ld)" ), name, ch );
1669 if( const std::optional<std::string> hint =
1671 add_msg( m_info, _( "%s at any time to see and edit keybindings relevant to "
1672 "the current context." ),
1673 *hint );
1674 }
1675 }
1676 }
1677 return false;
1678 }
1679
1680 // This has no action unless we're in a special game mode.
1681 gamemode->pre_action( act );
1682
1683 int soffset = get_option<int>( "MOVE_VIEW_OFFSET" );
1684
1685 int before_action_moves = u.moves;
1686
1687 // These actions are allowed while deathcam is active. Registered in game::get_player_input
1688 if( uquit == QUIT_WATCH || !u.is_dead_state() ) {
1689 switch( act ) {
1692 break;
1693
1694 case ACTION_CENTER:
1697 break;
1698
1699 case ACTION_SHIFT_N:
1700 case ACTION_SHIFT_NE:
1701 case ACTION_SHIFT_E:
1702 case ACTION_SHIFT_SE:
1703 case ACTION_SHIFT_S:
1704 case ACTION_SHIFT_SW:
1705 case ACTION_SHIFT_W:
1706 case ACTION_SHIFT_NW: {
1707 static const std::map<action_id, std::pair<point, point>> shift_delta = {
1716 };
1718 shift_delta.at( act ).second * soffset : shift_delta.at( act ).first * soffset;
1719 }
1720 break;
1721
1722 case ACTION_LOOK:
1723 look_around();
1724 break;
1725
1726 case ACTION_KEYBINDINGS:
1727 // already handled by input context
1728 break;
1729
1730 default:
1731 break;
1732 }
1733 }
1734
1735 // actions allowed only while alive
1736 if( !u.is_dead_state() ) {
1737 switch( act ) {
1738 case ACTION_NULL:
1739 case NUM_ACTIONS:
1740 break; // dummy entries
1741 case ACTION_ACTIONMENU:
1742 case ACTION_MAIN_MENU:
1743 case ACTION_KEYBINDINGS:
1744 break; // handled above
1745
1746 case ACTION_TIMEOUT:
1747 if( check_safe_mode_allowed( false ) ) {
1749 }
1750 break;
1751
1752 case ACTION_PAUSE:
1753 if( check_safe_mode_allowed() ) {
1755 }
1756 break;
1757
1758 case ACTION_CYCLE_MOVE:
1760 break;
1761
1762 case ACTION_RESET_MOVE:
1764 break;
1765
1766 case ACTION_TOGGLE_RUN:
1768 break;
1769
1772 break;
1773
1776 break;
1777
1778 case ACTION_MOVE_FORTH:
1780 case ACTION_MOVE_RIGHT:
1782 case ACTION_MOVE_BACK:
1784 case ACTION_MOVE_LEFT:
1786 if( !u.get_value( "remote_controlling" ).empty() &&
1790 } else if( veh_ctrl ) {
1791 // vehicle control uses x for steering and y for ac/deceleration,
1792 // so no rotation needed
1794 } else {
1796 if( auto_travel_mode && !u.is_auto_moving() ) {
1797 for( int i = 0; i < SEEX; i++ ) {
1798 tripoint auto_travel_destination( u.posx() + dest_delta.x * ( SEEX - i ),
1799 u.posy() + dest_delta.y * ( SEEX - i ),
1800 u.posz() );
1802 auto_travel_destination,
1804 u.get_path_avoid() );
1805 if( !destination_preview.empty() ) {
1808 break;
1809 }
1810 }
1813 if( dest_next == point_zero ) {
1815 }
1816 dest_delta = dest_next;
1817 }
1818 if( !avatar_action::move( u, m, dest_delta ) ) {
1819 // auto-move should be canceled due to a failed move or obstacle
1821 }
1822 }
1823 break;
1824 case ACTION_MOVE_DOWN:
1825 if( u.is_mounted() ) {
1826 auto mon = u.mounted_creature.get();
1827 if( !mon->has_flag( MF_RIDEABLE_MECH ) ) {
1828 add_msg( m_info, _( "You can't go down stairs while you're riding." ) );
1829 break;
1830 }
1831 }
1832 if( !u.in_vehicle ) {
1833 vertical_move( -1, false );
1834 } else if( veh_ctrl && vp->vehicle().is_rotorcraft() ) {
1836 }
1837 break;
1838
1839 case ACTION_MOVE_UP:
1840 if( u.is_mounted() ) {
1841 auto mon = u.mounted_creature.get();
1842 if( !mon->has_flag( MF_RIDEABLE_MECH ) ) {
1843 add_msg( m_info, _( "You can't go down stairs while you're riding." ) );
1844 break;
1845 }
1846 }
1847 if( !u.in_vehicle ) {
1848 vertical_move( 1, false );
1849 } else if( veh_ctrl && vp->vehicle().is_rotorcraft() ) {
1851 } else if( veh_ctrl && vp->vehicle().has_part( "ROTOR" ) &&
1852 !vp->vehicle().has_sufficient_rotorlift() ) {
1853 add_msg( m_bad, _( "The rotors struggle to generate enough lift!" ) );
1854 }
1855 break;
1856
1857 case ACTION_OPEN:
1859 add_msg( m_info, _( "You can't open things while you're in your shell." ) );
1860 } else if( u.is_mounted() ) {
1861 auto mon = u.mounted_creature.get();
1862 if( !mon->has_flag( MF_RIDEABLE_MECH ) ) {
1863 add_msg( m_info, _( "You can't open things while you're riding." ) );
1864 break;
1865 } else {
1866 open();
1867 }
1868 } else {
1869 open();
1870 }
1871 break;
1872
1873 case ACTION_CLOSE:
1875 add_msg( m_info, _( "You can't close things while you're in your shell." ) );
1876 } else if( u.is_mounted() ) {
1877 auto mon = u.mounted_creature.get();
1878 if( !mon->has_flag( MF_RIDEABLE_MECH ) ) {
1879 add_msg( m_info, _( "You can't close things while you're riding." ) );
1880 break;
1881 } else {
1882 close();
1883 }
1884 } else if( mouse_target ) {
1885 doors::close_door( m, u, *mouse_target );
1886 } else {
1887 close();
1888 }
1889 break;
1890
1891 case ACTION_SMASH:
1892 if( veh_ctrl ) {
1893 handbrake();
1894 } else if( u.has_active_mutation( trait_SHELL2 ) ) {
1895 add_msg( m_info, _( "You can't smash things while you're in your shell." ) );
1896 } else {
1897 smash();
1898 }
1899 break;
1900
1901 case ACTION_EXAMINE:
1903 add_msg( m_info, _( "You can't examine your surroundings while you're in your shell." ) );
1904 } else if( mouse_target ) {
1905 examine( *mouse_target );
1906 } else {
1907 examine();
1908 }
1909 break;
1910
1911 case ACTION_ADVANCEDINV:
1913 add_msg( m_info, _( "You can't move mass quantities while you're in your shell." ) );
1914 } else if( u.is_mounted() ) {
1915 add_msg( m_info, _( "You can't move mass quantities while you're riding." ) );
1916 } else {
1918 }
1919 break;
1920
1921 case ACTION_PICKUP:
1923 add_msg( m_info, _( "You can't pick anything up while you're in your shell." ) );
1924 } else if( u.is_mounted() ) {
1925 add_msg( m_info, _( "You can't pick anything up while you're riding." ) );
1926 } else if( mouse_target ) {
1927 pickup( *mouse_target );
1928 } else {
1929 pickup();
1930 }
1931 break;
1932
1933 case ACTION_PICKUP_FEET:
1935 add_msg( m_info, _( "You can't pick anything up while you're in your shell." ) );
1936 } else {
1937 pickup_feet();
1938 }
1939 break;
1940
1941 case ACTION_GRAB:
1943 add_msg( m_info, _( "You can't grab things while you're in your shell." ) );
1944 } else if( u.is_mounted() ) {
1945 auto mon = u.mounted_creature.get();
1946 if( !mon->has_flag( MF_RIDEABLE_MECH ) ) {
1947 add_msg( m_info, _( "You can't grab things while you're riding." ) );
1948 break;
1949 } else if( !mon->type->mech_weapon.is_empty() ) {
1950 add_msg( m_info, _( "Your mech doesn't have hands to grab with." ) );
1951 break;
1952 } else {
1953 grab();
1954 }
1955 } else {
1956 grab();
1957 }
1958 break;
1959
1960 case ACTION_HAUL:
1962 add_msg( m_info, _( "You can't haul things while you're in your shell." ) );
1963 } else if( u.is_mounted() ) {
1964 add_msg( m_info, _( "You can't haul things while you're riding." ) );
1965 } else {
1966 haul();
1967 }
1968 break;
1969
1970 case ACTION_BUTCHER:
1972 add_msg( m_info, _( "You can't butcher while you're in your shell." ) );
1973 } else if( u.is_mounted() ) {
1974 add_msg( m_info, _( "You can't butcher while you're riding." ) );
1975 } else {
1976 butcher();
1977 }
1978 break;
1979
1980 case ACTION_CHAT:
1981 chat();
1982 break;
1983
1984 case ACTION_PEEK:
1986 add_msg( m_info, _( "You can't peek around corners while you're in your shell." ) );
1987 } else if( u.is_mounted() ) {
1988 add_msg( m_info, _( "You can't peek around corners while you're riding." ) );
1989 } else {
1990 peek();
1991 }
1992 break;
1993
1994 case ACTION_LIST_ITEMS:
1996 break;
1997
1998 case ACTION_ZONES:
1999 zones_manager();
2000 break;
2001
2002 case ACTION_LOOT:
2003 loot();
2004 break;
2005
2006 case ACTION_INVENTORY:
2008 break;
2009
2010 case ACTION_COMPARE:
2011 game_menus::inv::compare( u, std::nullopt );
2012 break;
2013
2014 case ACTION_ORGANIZE:
2016 break;
2017
2018 case ACTION_USE:
2019 // Shell-users are presumed to be able to mess with their inventories, etc
2020 // while in the shell. Eating, gear-changing, and item use are OK.
2022 break;
2023
2024 case ACTION_USE_WIELDED:
2026 break;
2027
2028 case ACTION_WEAR:
2029 wear();
2030 break;
2031
2032 case ACTION_TAKE_OFF:
2033 takeoff();
2034 break;
2035
2036 case ACTION_EAT:
2037 if( !avatar_action::eat_here( u ) ) {
2039 }
2040 break;
2041
2043 if( !avatar_action::eat_here( u ) ) {
2045 }
2046 break;
2047
2048 case ACTION_READ:
2049 // Shell-users are presumed to have the book just at an opening and read it that way
2050 read();
2051 break;
2052
2053 case ACTION_WIELD:
2055 break;
2056
2057 case ACTION_PICK_STYLE:
2058 u.martial_arts_data->pick_style( u );
2059 break;
2060
2061 case ACTION_RELOAD_ITEM:
2063 break;
2064
2067 break;
2068
2071 break;
2072
2073 case ACTION_UNLOAD:
2075 break;
2076
2077 case ACTION_MEND:
2079 break;
2080
2081 case ACTION_THROW: {
2082 item_location loc;
2083 avatar_action::plthrow( g->u, loc );
2084 break;
2085 }
2086
2087 case ACTION_FIRE:
2088 fire();
2089 break;
2090
2091 case ACTION_CAST_SPELL:
2092 cast_spell();
2093 break;
2094
2095 case ACTION_FIRE_BURST: {
2096 if( u.primary_weapon().gun_set_mode( gun_mode_id( "AUTO" ) ) ) {
2098 }
2099 break;
2100 }
2101
2103 if( u.is_armed() && u.primary_weapon().is_gun() && !u.primary_weapon().is_gunmod() ) {
2104 if( u.primary_weapon().gun_all_modes().size() > 1 ) {
2106 } else {
2107 add_msg( m_info, _( "Your %s has only one firing mode." ), u.primary_weapon().display_name() );
2108 }
2109 }
2110 break;
2111
2113 if( u.is_armed() && u.primary_weapon().is_gun() && !u.primary_weapon().is_gunmod() ) {
2115 }
2116 break;
2117
2118 case ACTION_DROP:
2119 // You CAN drop things to your own tile while in the shell.
2120 drop();
2121 break;
2122
2123 case ACTION_DIR_DROP:
2125 add_msg( m_info, _( "You can't drop things to another tile while you're in your shell." ) );
2126 } else {
2128 }
2129 break;
2130 case ACTION_BIONICS:
2131 show_bionics_ui( u );
2132 break;
2133 case ACTION_MUTATIONS:
2135 break;
2136
2137 case ACTION_SORT_ARMOR:
2139 break;
2140
2141 case ACTION_WAIT:
2142 wait();
2143 break;
2144
2145 case ACTION_CRAFT:
2147 add_msg( m_info, _( "You can't craft while you're in your shell." ) );
2148 } else if( u.is_mounted() ) {
2149 add_msg( m_info, _( "You can't craft while you're riding." ) );
2150 } else {
2151 u.craft();
2152 }
2153 break;
2154
2155 case ACTION_RECRAFT:
2157 add_msg( m_info, _( "You can't craft while you're in your shell." ) );
2158 } else if( u.is_mounted() ) {
2159 add_msg( m_info, _( "You can't craft while you're riding." ) );
2160 } else {
2161 u.recraft();
2162 }
2163 break;
2164
2165 case ACTION_LONGCRAFT:
2167 add_msg( m_info, _( "You can't craft while you're in your shell." ) );
2168 } else if( u.is_mounted() ) {
2169 add_msg( m_info, _( "You can't craft while you're riding." ) );
2170 } else {
2171 u.long_craft();
2172 }
2173 break;
2174
2175 case ACTION_DISASSEMBLE:
2176 if( u.controlling_vehicle ) {
2177 add_msg( m_info, _( "You can't disassemble items while driving." ) );
2178 } else if( u.is_mounted() ) {
2179 add_msg( m_info, _( "You can't disassemble items while you're riding." ) );
2180 } else {
2182 }
2183 break;
2184
2185 case ACTION_CONSTRUCT:
2186 if( u.in_vehicle ) {
2187 add_msg( m_info, _( "You can't construct while in a vehicle." ) );
2188 } else if( u.has_active_mutation( trait_SHELL2 ) ) {
2189 add_msg( m_info, _( "You can't construct while you're in your shell." ) );
2190 } else if( u.is_mounted() ) {
2191 add_msg( m_info, _( "You can't construct while you're riding." ) );
2192 } else {
2193 construction_menu( false );
2194 }
2195 break;
2196
2197 case ACTION_SLEEP:
2198 if( veh_ctrl ) {
2199 add_msg( m_info, _( "Vehicle control has moved, %s" ),
2200 press_x( ACTION_CONTROL_VEHICLE, _( "new binding is " ),
2201 _( "new default binding is '^'." ) ) );
2202 } else {
2203 sleep();
2204 }
2205 break;
2206
2209 add_msg( m_info, _( "You can't operate a vehicle while you're in your shell." ) );
2210 } else if( u.is_mounted() ) {
2211 u.dismount();
2212 } else {
2214 }
2215 break;
2216
2219 add_msg( m_info, auto_travel_mode ? _( "Auto travel mode ON!" ) : _( "Auto travel mode OFF!" ) );
2220 break;
2221
2223 if( safe_mode == SAFE_MODE_OFF ) {
2225 mostseen = 0;
2226 add_msg( m_info, _( "Safe mode ON!" ) );
2227 } else {
2230 add_msg( m_info, get_option<bool>( "AUTOSAFEMODE" )
2231 ? _( "Safe mode OFF! (Auto safe mode still enabled!)" ) : _( "Safe mode OFF!" ) );
2232 }
2236 }
2237 break;
2238
2240 auto &autosafemode_option = get_options().get_option( "AUTOSAFEMODE" );
2241 add_msg( m_info, autosafemode_option.value_as<bool>()
2242 ? _( "Auto safe mode OFF!" ) : _( "Auto safe mode ON!" ) );
2243 autosafemode_option.setNext();
2244 break;
2245 }
2246
2248 if( safe_mode == SAFE_MODE_STOP ) {
2249 add_msg( m_info, _( "Ignoring enemy!" ) );
2250 for( auto &elem : u.get_mon_visible().new_seen_mon ) {
2251 monster &critter = *elem;
2252 critter.ignoring = rl_dist( u.pos(), critter.pos() );
2253 }
2255 } else if( u.has_effect( effect_laserlocked ) ) {
2256 if( u.has_trait( trait_PROF_CHURL ) ) {
2257 add_msg( m_warning, _( "You make the sign of the cross." ) );
2258 } else {
2259 add_msg( m_info, _( "Ignoring laser targeting!" ) );
2260 }
2263 }
2264 break;
2265
2267 if( safe_mode == SAFE_MODE_STOP && !get_safemode().empty() ) {
2269 add_msg( m_info, _( "Creature whitelisted: %s" ), get_safemode().lastmon_whitelist );
2271 mostseen = 0;
2272 } else {
2273 get_safemode().show();
2274 }
2275 break;
2276
2277 case ACTION_SUICIDE:
2278 if( query_yn( _( "Commit suicide?" ) ) ) {
2279 if( query_yn( _( "REALLY commit suicide?" ) ) ) {
2280 u.apply_damage( &u, body_part_head, 99999 );
2281 u.moves = 0;
2282 u.place_corpse();
2284 }
2285 }
2286 break;
2287
2288 case ACTION_SAVE:
2289 if( query_yn( _( "Save and quit?" ) ) ) {
2290 if( save() ) {
2291 u.moves = 0;
2292 uquit = QUIT_SAVED;
2293 }
2294 }
2295 break;
2296
2297 case ACTION_QUICKSAVE:
2298 quicksave();
2299 return false;
2300
2301 case ACTION_QUICKLOAD:
2302 quickload();
2303 return false;
2304
2305 case ACTION_PL_INFO:
2307 break;
2308
2309 case ACTION_MAP:
2311 break;
2312
2313 case ACTION_SKY:
2314 if( m.is_outside( u.pos() ) ) {
2316 } else {
2317 add_msg( m_info, _( "You can't see the sky from here." ) );
2318 }
2319 break;
2320
2321 case ACTION_MISSIONS:
2322 list_missions();
2323 break;
2324
2325 case ACTION_SCORES:
2327 break;
2328
2329 case ACTION_DIARY:
2331 break;
2332
2333 case ACTION_FACTIONS:
2334 faction_manager_ptr->display();
2335 break;
2336
2337 case ACTION_MORALE:
2338 u.disp_morale();
2339 break;
2340
2341 case ACTION_MESSAGES:
2343 break;
2344
2345 case ACTION_HELP:
2347 break;
2348
2349 case ACTION_OPTIONS:
2350 get_options().show( true );
2351 break;
2352
2353 case ACTION_AUTOPICKUP:
2355 break;
2356
2357 case ACTION_AUTONOTES:
2359 break;
2360
2361 case ACTION_SAFEMODE:
2362 get_safemode().show();
2363 break;
2364
2367 break;
2368
2369 case ACTION_COLOR:
2370 all_colors.show_gui();
2371 break;
2372
2373 case ACTION_WORLD_MODS:
2374 world_generator->show_active_world_mods( world_generator->active_world->active_mod_order );
2375 break;
2376
2377 case ACTION_DEBUG:
2379 break; //don't do anything when sharing and not debugger
2380 }
2382 break;
2383
2384 case ACTION_LUA_CONSOLE:
2386 break;
2387
2388 case ACTION_LUA_RELOAD:
2390 break;
2391
2394 break;
2395
2398 break;
2399
2402 break;
2403
2405 reload_tileset( []( std::string str ) {
2406 DebugLog( DL::Info, DC::Main ) << str;
2407 } );
2408 break;
2409
2411 get_options().get_option( "AUTO_FEATURES" ).setNext();
2412 get_options().save();
2413 //~ Auto Features are now ON/OFF
2414 add_msg( _( "%s are now %s." ),
2415 get_options().get_option( "AUTO_FEATURES" ).getMenuText(),
2416 get_option<bool>( "AUTO_FEATURES" ) ? _( "ON" ) : _( "OFF" ) );
2417 break;
2418
2420 get_options().get_option( "AUTO_PULP_BUTCHER" ).setNext();
2421 get_options().save();
2422 //~ Auto Pulp/Pulp Adjacent/Butcher is now set to x
2423 add_msg( _( "%s is now set to %s." ),
2424 get_options().get_option( "AUTO_PULP_BUTCHER" ).getMenuText(),
2425 get_options().get_option( "AUTO_PULP_BUTCHER" ).getValueName() );
2426 break;
2427
2429 get_options().get_option( "AUTO_MINING" ).setNext();
2430 get_options().save();
2431 //~ Auto Mining is now ON/OFF
2432 add_msg( _( "%s is now %s." ),
2433 get_options().get_option( "AUTO_MINING" ).getMenuText(),
2434 get_option<bool>( "AUTO_MINING" ) ? _( "ON" ) : _( "OFF" ) );
2435 break;
2436
2438 if( g->u.get_value( "THIEF_MODE" ) == "THIEF_ASK" ) {
2439 u.set_value( "THIEF_MODE", "THIEF_HONEST" );
2440 u.set_value( "THIEF_MODE_KEEP", "YES" );
2441 //~ Thief mode cycled between THIEF_ASK/THIEF_HONEST/THIEF_STEAL
2442 add_msg( _( "You will not pick up other peoples belongings." ) );
2443 } else if( g->u.get_value( "THIEF_MODE" ) == "THIEF_HONEST" ) {
2444 u.set_value( "THIEF_MODE", "THIEF_STEAL" );
2445 u.set_value( "THIEF_MODE_KEEP", "YES" );
2446 //~ Thief mode cycled between THIEF_ASK/THIEF_HONEST/THIEF_STEAL
2447 add_msg( _( "You will pick up also those things that belong to others!" ) );
2448 } else if( g->u.get_value( "THIEF_MODE" ) == "THIEF_STEAL" ) {
2449 u.set_value( "THIEF_MODE", "THIEF_ASK" );
2450 u.set_value( "THIEF_MODE_KEEP", "NO" );
2451 //~ Thief mode cycled between THIEF_ASK/THIEF_HONEST/THIEF_STEAL
2452 add_msg( _( "You will be reminded not to steal." ) );
2453 } else {
2454 // ERROR
2455 add_msg( _( "THIEF_MODE CONTAINED BAD VALUE [ %s ]!" ), g->u.get_value( "THIEF_MODE" ) );
2456 }
2457 break;
2458
2460 get_options().get_option( "AUTO_FORAGING" ).setNext();
2461 get_options().save();
2462 //~ Auto Foraging is now set to x
2463 add_msg( _( "%s is now set to %s." ),
2464 get_options().get_option( "AUTO_FORAGING" ).getMenuText(),
2465 get_options().get_option( "AUTO_FORAGING" ).getValueName() );
2466 break;
2467
2469 get_options().get_option( "AUTO_PICKUP" ).setNext();
2470 get_options().save();
2471 //~ Auto pickup is now set to x
2472 add_msg( _( "%s is now set to %s." ),
2473 get_options().get_option( "AUTO_PICKUP" ).getMenuText(),
2474 get_options().get_option( "AUTO_PICKUP" ).getValueName() );
2475 break;
2476
2479 break; //don't do anything when sharing and not debugger
2480 }
2481 display_scent();
2482 break;
2483
2486 break; //don't do anything when sharing and not debugger
2487 }
2488 display_scent();
2489 break;
2490
2493 break; //don't do anything when sharing and not debugger
2494 }
2496 break;
2499 break; //don't do anything when sharing and not debugger
2500 }
2502 break;
2505 break; //don't do anything when sharing and not debugger
2506 }
2508 break;
2509
2512 break; //don't do anything when sharing and not debugger
2513 }
2515 break;
2516
2519 break; //don't do anything when sharing and not debugger
2520 }
2522 break;
2523
2526 break; //don't do anything when sharing and not debugger
2527 }
2529 break;
2530
2532 g->debug_submap_grid_overlay = !g->debug_submap_grid_overlay;
2533 break;
2534
2537 break;
2538
2541 break; //don't do anything when sharing and not debugger
2542 }
2544 if( debug_mode ) {
2545 add_msg( m_info, _( "Debug mode ON!" ) );
2546 } else {
2547 add_msg( m_info, _( "Debug mode OFF!" ) );
2548 }
2549 break;
2550
2551 case ACTION_ZOOM_IN:
2552 zoom_in();
2554 break;
2555
2556 case ACTION_ZOOM_OUT:
2557 zoom_out();
2559 break;
2560
2561 case ACTION_ITEMACTION:
2563 break;
2564
2565 case ACTION_AUTOATTACK:
2567 break;
2568
2569 default:
2570 break;
2571 }
2572 }
2573 if( act != ACTION_TIMEOUT ) {
2574 u.mod_moves( -current_turn.moves_elapsed() );
2575 }
2576 gamemode->post_action( act );
2577
2578 u.movecounter = ( !u.is_dead_state() ? ( before_action_moves - u.moves ) : 0 );
2579 dbg( DL::Info ) << string_format( "%s: [%d] %d - %d = %d", action_ident( act ),
2580 to_turn<int>( calendar::turn ), before_action_moves, u.movecounter, u.moves );
2581 return ( !u.is_dead_state() );
2582}
bool can_action_change_worldstate(const action_id act)
Lookup whether an action can affect the state of the game world.
Definition: action.cpp:358
action_id look_up_action(const std::string &ident)
Lookup an action ID by its unique string identifier.
Definition: action.cpp:431
action_id handle_main_menu()
Show in-game main menu.
Definition: action.cpp:919
point get_delta_from_movement_action(const action_id act, const iso_rotate rot)
Definition: action.cpp:520
std::optional< std::string > press_x_if_bound(action_id act)
Definition: action.cpp:482
action_id handle_action_menu()
Show the action menu.
Definition: action.cpp:695
@ ACTION_SAFEMODE
Open safemode manager.
Definition: action.h:263
@ ACTION_PEEK
Peek through something (e.g.
Definition: action.h:117
@ ACTION_OPEN
Open an item (e.g.
Definition: action.h:95
@ ACTION_CRAFT
Open crafting menu.
Definition: action.h:195
@ ACTION_DROP
Open the drop-item menu.
Definition: action.h:177
@ ACTION_READ
Open the read menu.
Definition: action.h:149
@ ACTION_TOGGLE_AUTO_PICKUP
Turn auto pickup on/off.
Definition: action.h:313
@ ACTION_MOVE_BACK_LEFT
Move towards bottom-left of screen / decelerate and steer left.
Definition: action.h:47
@ ACTION_ZOOM_IN
Zoom view out.
Definition: action.h:291
@ ACTION_EAT
Open the default consume item menu.
Definition: action.h:145
@ ACTION_SMASH
Smash something.
Definition: action.h:99
@ ACTION_ADVANCEDINV
Open the advanced inventory screen.
Definition: action.h:131
@ ACTION_LUA_RELOAD
Hot-reload Lua code.
Definition: action.h:281
@ ACTION_QUICKSAVE
Quicksave the game.
Definition: action.h:223
@ ACTION_HELP
Display help screen.
Definition: action.h:249
@ ACTION_MESSAGES
Display messages screen.
Definition: action.h:247
@ ACTION_ZONES
Open the zone manager.
Definition: action.h:121
@ ACTION_TOGGLE_PIXEL_MINIMAP
Turn pixel minimap on/off.
Definition: action.h:297
@ ACTION_USE
Open the use menu.
Definition: action.h:137
@ ACTION_QUICKLOAD
Quickload the game.
Definition: action.h:225
@ ACTION_LIST_ITEMS
List items and monsters in a given square.
Definition: action.h:119
@ ACTION_DEBUG
Open debug menu.
Definition: action.h:277
@ ACTION_OPTIONS
Display options window.
Definition: action.h:257
@ ACTION_MOVE_FORTH
Move towards top of screen / accelerate.
Definition: action.h:37
@ ACTION_PICK_STYLE
Open the martial-arts style menu.
Definition: action.h:153
@ ACTION_CONSTRUCT
Open construct menu.
Definition: action.h:201
@ ACTION_MOVE_FORTH_RIGHT
Move towards top-right of screen / accelerate and steer right.
Definition: action.h:39
@ ACTION_SORT_ARMOR
Open the armor sorting menu.
Definition: action.h:185
@ ACTION_OPEN_CONSUME
Open the custom consume item menu.
Definition: action.h:147
@ ACTION_MORALE
Display morale effects screen.
Definition: action.h:245
@ ACTION_NULL
Invalid action used for various lookup errors.
Definition: action.h:20
@ ACTION_RESET_MOVE
Reset movement mode to walk
Definition: action.h:59
@ ACTION_CHAT
Chat with something.
Definition: action.h:113
@ ACTION_RELOAD_WIELDED
Attempt to reload wielded object.
Definition: action.h:159
@ ACTION_MOVE_DOWN
Descend a staircase.
Definition: action.h:53
@ ACTION_MISSIONS
Display missions screen.
Definition: action.h:239
@ ACTION_AUTONOTES
Open autonotes manager.
Definition: action.h:261
@ ACTION_WIELD
Open the wield menu.
Definition: action.h:151
@ ACTION_THROW
Open the throw menu.
Definition: action.h:165
@ ACTION_TOGGLE_AUTO_MINING
Turn auto mining on/off.
Definition: action.h:309
@ ACTION_INVENTORY
Open the primary inventory screen.
Definition: action.h:129
@ ACTION_TOGGLE_AUTOSAFE
Turn automatic triggering of safemode on/off.
Definition: action.h:213
@ ACTION_OPEN_MOVEMENT
Open movement mode menu.
Definition: action.h:65
@ ACTION_COMPARE
Open the item compare screen.
Definition: action.h:133
@ ACTION_SCORES
Display scores screen.
Definition: action.h:241
@ ACTION_BUTCHER
Butcher or disassemble objects in current square.
Definition: action.h:111
@ ACTION_SEC_SELECT
Click on a point with secondary mouse button (usually right button)
Definition: action.h:27
@ ACTION_TOGGLE_CROUCH
Toggle crouch on/off.
Definition: action.h:63
@ ACTION_TOGGLE_HOUR_TIMER
Toggle timing of the game hours.
Definition: action.h:329
@ ACTION_SELECT
Click on a point with primary mouse button (usually left button)
Definition: action.h:25
@ ACTION_MAIN_MENU
Display main menu.
Definition: action.h:251
@ ACTION_DISPLAY_SUBMAP_GRID
Toggle submap grid overlay.
Definition: action.h:327
@ ACTION_WAIT
Open wait menu.
Definition: action.h:193
@ ACTION_ACTIONMENU
Open the action menu.
Definition: action.h:293
@ ACTION_DISASSEMBLE
Open disassemble menu.
Definition: action.h:203
@ ACTION_LOOT
Sort out the loot.
Definition: action.h:123
@ ACTION_TOGGLE_FULLSCREEN
Toggle full-screen mode.
Definition: action.h:275
@ ACTION_MAP
Display over-map.
Definition: action.h:235
@ ACTION_MEND
Open the mending menu (e.g.
Definition: action.h:163
@ ACTION_TOGGLE_THIEF_MODE
Toggle permanent attitude to stealing.
Definition: action.h:215
@ ACTION_USE_WIELDED
Use currently wielded item.
Definition: action.h:139
@ ACTION_PL_INFO
Display player status screen.
Definition: action.h:233
@ ACTION_DISPLAY_SCENT_TYPE
Toggle scent type map.
Definition: action.h:285
@ ACTION_TOGGLE_AUTO_FORAGING
Turn auto foraging on/off.
Definition: action.h:311
@ ACTION_FIRE_BURST
Burst-fire the current weapon.
Definition: action.h:169
@ ACTION_BIONICS
Open the bionics menu.
Definition: action.h:181
@ ACTION_CONTROL_VEHICLE
Open vehicle control menu.
Definition: action.h:207
@ ACTION_SAVE
Save the game and quit.
Definition: action.h:221
@ ACTION_MOVE_UP
Ascend a staircase.
Definition: action.h:55
@ ACTION_TOGGLE_PANEL_ADM
Turn admin panel on/off.
Definition: action.h:299
@ ACTION_TOGGLE_AUTO_PULP_BUTCHER
Change auto pulp/butcher mode.
Definition: action.h:307
@ ACTION_TOGGLE_AUTO_TRAVEL_MODE
Turn auto travel mode on/off.
Definition: action.h:209
@ ACTION_COLOR
Open color manager.
Definition: action.h:265
@ ACTION_TIMEOUT
Input timeout.
Definition: action.h:35
@ ACTION_TOGGLE_RUN
Toggle run on/off.
Definition: action.h:61
@ ACTION_FACTIONS
Display factions screen.
Definition: action.h:243
@ ACTION_GRAB
Grab or let go of an object.
Definition: action.h:107
@ ACTION_MOVE_BACK
Move towards bottom of screen / decelerate.
Definition: action.h:45
@ ACTION_CAST_SPELL
Cast a spell (only if any spells are known)
Definition: action.h:175
@ ACTION_DIR_DROP
Drop items in a given direction.
Definition: action.h:179
@ ACTION_AUTOATTACK
Auto select and attack hostile creature within range.
Definition: action.h:187
@ ACTION_CYCLE_MOVE
Cycle run/walk/crouch mode.
Definition: action.h:57
@ ACTION_SKY
Show sky state for trying to predict weather.
Definition: action.h:237
@ ACTION_LUA_CONSOLE
Open Lua console.
Definition: action.h:279
@ ACTION_FIRE
Fire the wielded weapon, or open fire menu if none.
Definition: action.h:167
@ ACTION_PAUSE
Pause an on-going activity.
Definition: action.h:33
@ ACTION_MOVE_BACK_RIGHT
Move towards bottom-right of screen / decelerate and steer right.
Definition: action.h:43
@ ACTION_MUTATIONS
Open the mutations menu.
Definition: action.h:183
@ ACTION_HAUL
Haul pile of items, or let go of them.
Definition: action.h:109
@ ACTION_MOVE_RIGHT
Move / steer right.
Definition: action.h:41
@ ACTION_SLEEP
Open sleep menu.
Definition: action.h:205
@ ACTION_ITEMACTION
Open the item uses menu.
Definition: action.h:295
@ ACTION_MOVE_LEFT
Move / steer left.
Definition: action.h:49
@ ACTION_SELECT_DEFAULT_AMMO
Change default ammo for current weapon.
Definition: action.h:173
@ ACTION_AUTOPICKUP
Open autopickup manager.
Definition: action.h:259
@ ACTION_SUICIDE
Commit suicide.
Definition: action.h:227
@ NUM_ACTIONS
Not an action, serves as count of enumerated actions.
Definition: action.h:331
@ ACTION_ZOOM_OUT
Zoom view in.
Definition: action.h:289
@ ACTION_SELECT_FIRE_MODE
Change fire mode of the current weapon.
Definition: action.h:171
@ ACTION_UNLOAD
Open the unload item (e.g.
Definition: action.h:161
@ ACTION_RECRAFT
Repeat last craft command.
Definition: action.h:197
@ ACTION_TAKE_OFF
Open the take-off clothing selection menu.
Definition: action.h:143
@ ACTION_PICKUP_FEET
Pick up items from current square.
Definition: action.h:105
@ ACTION_TOGGLE_AUTO_FEATURES
Turn auto features on/off.
Definition: action.h:305
@ ACTION_WORLD_MODS
Open active world mods.
Definition: action.h:267
@ ACTION_TOGGLE_DEBUG_MODE
Toggle debug mode.
Definition: action.h:287
@ ACTION_ORGANIZE
Swap inventory letters.
Definition: action.h:135
@ ACTION_MOVE_FORTH_LEFT
Move towards top-left of screen / accelerate and steer left.
Definition: action.h:51
@ ACTION_RELOAD_TILESET
Reload current tileset.
Definition: action.h:303
@ ACTION_CLOSE
Close an item (e.g.
Definition: action.h:97
@ ACTION_RELOAD_WEAPON
Attempt to reload wielded weapon, then fall back to the load item select menu.
Definition: action.h:157
@ ACTION_RELOAD_ITEM
Open the load item (e.g.
Definition: action.h:155
@ ACTION_PICKUP
Pick up items from current/adjacent squares.
Definition: action.h:103
@ ACTION_LONGCRAFT
Open batch crafting menu.
Definition: action.h:199
@ ACTION_DISTRACTION_MANAGER
Open distraction manager.
Definition: action.h:269
@ ACTION_WEAR
Open the wear clothing selection menu.
Definition: action.h:141
@ ACTION_DIARY
Display diary window.
Definition: action.h:253
void create_advanced_inv()
void show_armor_layers_ui(Character &who)
auto_notes::auto_note_settings & get_auto_notes_settings()
Definition: auto_note.cpp:386
auto_pickup::player_settings & get_auto_pickup()
Definition: auto_pickup.cpp:38
void show_bionics_ui(Character &who)
Definition: bionics_ui.cpp:537
const bodypart_str_id body_part_head("head")
bool tile_iso
Using isometric tileset.
bool debug_mode
Extended debugging mode, can be toggled during game.
bool has_active_mutation(const trait_id &b) const
Definition: mutation.cpp:365
pimpl< character_martial_arts > martial_arts_data
Definition: character.h:1586
bool has_active_item(const itype_id &id) const
Whether the player carries an active item of the given item type.
Definition: character.cpp:2510
void place_corpse()
std::set< tripoint > get_path_avoid() const override
Returns a set of points we do not want to path through.
Definition: character.cpp:9961
bool has_destination_activity() const
bool is_auto_moving() const
void start_destination_activity()
action_id get_next_auto_move_direction()
item & primary_weapon()
Legacy code hack, don't use.
Definition: melee.cpp:167
const pathfinding_settings & get_pathfinding_settings() const override
Returns settings for pathfinding.
Definition: character.cpp:9975
bool is_armed() const
Returns true if the character is wielding something.
Definition: melee.cpp:206
void dismount()
Definition: character.cpp:1186
void set_value(const std::string &key, const std::string &value)
Definition: creature.cpp:1372
std::string get_value(const std::string &key) const
Definition: creature.cpp:1382
void mod_moves(int nmoves)
Definition: creature.cpp:1449
void cycle_move_mode()
Definition: avatar.cpp:1188
void toggle_map_memory()
Definition: avatar.cpp:123
void toggle_crouch_mode()
Definition: avatar.cpp:1172
void toggle_run_mode()
Definition: avatar.cpp:1163
void disp_morale()
Provides the window and detailed morale data.
Definition: avatar.cpp:1002
void reset_move_mode()
Definition: avatar.cpp:1181
static void show_diary_ui(diary *c_diary)
Definition: diary_ui.cpp:164
void item_action_menu()
void display_radiation()
Definition: game.cpp:11302
void list_missions()
Definition: mission_ui.cpp:22
input_context get_player_input(std::string &action)
bool try_get_left_click_action(action_id &act, const tripoint &mouse_target)
Definition: game.cpp:2294
void set_safe_mode(safe_mode_type mode)
Definition: game.cpp:8651
void reload_tileset(std::function< void(std::string)> out)
Definition: game.cpp:431
void pickup_feet()
Definition: game.cpp:5651
void zones_manager()
Definition: game.cpp:6124
int turnssincelastmon
Definition: game.h:1020
void display_visibility()
Definition: game.cpp:11216
void display_scent()
Definition: game.cpp:11181
bool save()
Returns false if saving failed.
Definition: game.cpp:2746
void butcher()
Definition: game.cpp:8333
void display_temperature()
Definition: game.cpp:11202
bool auto_travel_mode
Definition: game.h:1017
void zoom_out()
Definition: game.cpp:7074
void toggle_pixel_minimap()
Definition: game.cpp:420
void toggle_debug_hour_timer()
Definition: game.cpp:11248
void display_transparency()
Definition: game.cpp:11309
void list_items_monsters()
Definition: game.cpp:7252
void chat()
Definition: npctalk.cpp:397
void quickload()
Definition: game.cpp:11344
void pickup()
Definition: game.cpp:5629
void vertical_move(int z, bool force, bool peeking=false)
Moves the player vertically.
Definition: game.cpp:10014
void open_consume_item_menu()
void display_lighting()
Definition: game.cpp:11276
void control_vehicle()
Definition: game.cpp:5183
void peek()
Definition: game.cpp:5658
void drop()
Definition: game.cpp:8071
bool try_get_right_click_action(action_id &act, const tripoint &mouse_target)
Definition: game.cpp:2322
bool check_safe_mode_allowed(bool repeat_safe_mode_warnings=true)
Check whether movement is allowed according to safe mode settings.
Definition: game.cpp:8589
void zoom_in()
Definition: game.cpp:7086
void toggle_fullscreen()
Definition: game.cpp:410
void display_vehicle_ai()
Definition: game.cpp:11209
void mark_main_ui_adaptor_resize() const
Definition: game.cpp:2997
void drop_in_direction()
Definition: game.cpp:8076
void display_help()
Definition: help.cpp:140
input_event get_raw_input()
Temporary method to retrieve the raw input received, so that input_contexts can be used in screens wh...
Definition: input.cpp:1293
action_id display_menu(bool permit_execute_action=false)
Displays the possible actions in the current context and their keybindings.
Definition: input.cpp:993
std::optional< tripoint > get_coordinates(const catacurses::window &capture_win_)
Get the coordinates associated with the last mouse click (if any).
Definition: input.cpp:1332
std::string get_keyname(int ch, input_event_t inp_type, bool portable=false) const
Get the key name associated with the given keyboard keycode.
Definition: input.cpp:410
bool is_gun() const
Can this item be used to perform a ranged attack?
Definition: item.cpp:6527
void gun_cycle_mode()
Switch to the next available firing mode.
Definition: item.cpp:7921
std::string display_name(unsigned int quantity=1) const
Returns the item name and the charges or contained charges (if the item can have charges at all).
Definition: item.cpp:4847
bool is_gunmod() const
Definition: item.cpp:6557
std::map< gun_mode_id, gun_mode > gun_all_modes() const
Get all possible modes for this gun inclusive of any attached gunmods.
Definition: item.cpp:7840
bool gun_set_mode(const gun_mode_id &mode)
Try to set the mode for a gun, returning false if no such mode is possible.
Definition: item.cpp:7912
bool is_outside(const tripoint &p) const
Definition: map.cpp:2626
std::vector< tripoint > route(const tripoint &f, const tripoint &t, const pathfinding_settings &settings, const std::set< tripoint > &pre_closed={{ }}) const
Calculate the best path using A*.
const tripoint & pos() const override
Definition: monster.cpp:252
short ignoring
Definition: monster.h:505
cOpt & get_option(const std::string &name)
Definition: options.cpp:3396
std::string show(bool ingame=false, bool world_options_only=false, const std::function< bool()> &on_quit=nullptr)
Definition: options.cpp:2773
void show_adm()
Definition: panels.cpp:2298
void craft(const tripoint &loc=tripoint_zero)
Start various types of crafts.
Definition: crafting.cpp:342
int movecounter
Definition: player.h:247
void recraft(const tripoint &loc=tripoint_zero)
Definition: crafting.cpp:353
void long_craft(const tripoint &loc=tripoint_zero)
Definition: crafting.cpp:362
void add_rule(const std::string &rule_in, Creature::Attitude attitude_in, int proximity_in, rule_state state_in)
void show()
Definition: safemode_ui.cpp:39
int moves_elapsed()
#define all_colors
Definition: color.h:15
std::optional< construction_id > construction_menu(const bool blueprint)
@ Info
Information (default: enabled).
@ Main
Generic messages related to game startup and operation.
#define DebugLog(lev, cl)
DebugLog.
Definition: debug.h:285
@ RULE_WHITELISTED
Definition: enums.h:53
@ SAFE_MODE_OFF
Definition: game.h:77
@ QUIT_SAVED
Definition: game.h:70
static void open_movement_mode_menu()
static void smash()
static void open()
static void rcdrive(point d)
#define dbg(x)
static void takeoff()
static void read()
static void wait()
static const efftype_id effect_laserlocked("laserlocked")
static void wear()
static void close()
static const bionic_id bio_remote("bio_remote")
static void pldrive(const tripoint &p)
static void haul()
static const trait_id trait_SHELL2("SHELL2")
static const trait_id trait_PROF_CHURL("PROF_CHURL")
static void cast_spell()
static void loot()
static void fire()
static void grab()
static const itype_id itype_radiocontrol("radiocontrol")
help & get_help()
Definition: help.cpp:30
void show_mutations_ui(Character &who)
bool isDebugger()
Definition: mapsharing.cpp:65
bool isCompetitive()
Definition: mapsharing.cpp:35
void reload_wielded(bool prompt=false)
Reload wielded item.
void reload_item()
Prompt to reload some item.
void use_item(avatar &you, item_location &loc)
bool eat_here(avatar &you)
void wield()
Prompt to wield some item.
void plthrow(avatar &you, item_location loc, const std::optional< tripoint > &blind_throw_from_pos=std::nullopt)
void autoattack(avatar &you, map &m)
void eat(avatar &you)
Eat food or fuel 'E' (or 'a')
void fire_wielded_weapon(avatar &you)
Checks if the wielded weapon is a gun and can be fired then starts interactive aiming.
void reload_weapon(bool try_everything=true)
Reload a wielded gun/tool.
void mend(avatar &you, item_location loc)
void unload(avatar &you)
Prompts to unload some item.
void use_item(avatar &you, item_location loc)
Use a tool at given location.
void show_lua_console()
Definition: catalua.cpp:41
void reload_lua_code()
Definition: catalua.cpp:50
void disp_info(Character &ch)
Handles and displays detailed character info for the '@' screen.
void do_pause(Character &who)
Do pause action ('.
void debug()
void close_door(map &m, Character &who, const tripoint &closep)
Handles deducting moves, printing messages (only non-NPCs cause messages), actually closing it,...
Definition: gates.cpp:257
void common(avatar &you)
void compare(player &p, const std::optional< tripoint > &offset)
void swap_letters(player &p)
void prompt_select_default_ammo_for(avatar &u, const item &w)
Prompts to select default ammo compatible with provided gun.
Definition: ranged.cpp:3805
void display_visible_weather()
Display overmap like with display() and display the weather that is within line of sight.
void display()
Display overmap centered at the player's position.
options_manager & get_options()
Definition: options.cpp:146
T get_option(const std::string &name)
Definition: options.h:368
static constexpr point point_south_west
Definition: point.h:267
static constexpr point point_north_east
Definition: point.h:263
static constexpr point point_north_west
Definition: point.h:269
@ sleep
Will recharge only when character is asleep.
An instance of an input, like a keypress etc.
Definition: input.h:91
std::vector< int > sequence
Definition: input.h:97
int get_first_input() const
Definition: input.cpp:100
input_event_t type
Definition: input.h:92
void handbrake()

References _, Creature::A_ANY, achievements_tracker_ptr, act, action, ACTION_ACTIONMENU, ACTION_ADVANCEDINV, ACTION_AUTOATTACK, ACTION_AUTONOTES, ACTION_AUTOPICKUP, ACTION_BIONICS, ACTION_BUTCHER, ACTION_CAST_SPELL, ACTION_CENTER, ACTION_CHAT, ACTION_CLOSE, ACTION_COLOR, ACTION_COMPARE, ACTION_CONSTRUCT, ACTION_CONTROL_VEHICLE, ACTION_CRAFT, ACTION_CYCLE_MOVE, ACTION_DEBUG, ACTION_DIARY, ACTION_DIR_DROP, ACTION_DISASSEMBLE, ACTION_DISPLAY_LIGHTING, ACTION_DISPLAY_RADIATION, ACTION_DISPLAY_SCENT, ACTION_DISPLAY_SCENT_TYPE, ACTION_DISPLAY_SUBMAP_GRID, ACTION_DISPLAY_TEMPERATURE, ACTION_DISPLAY_TRANSPARENCY, ACTION_DISPLAY_VEHICLE_AI, ACTION_DISPLAY_VISIBILITY, ACTION_DISTRACTION_MANAGER, ACTION_DROP, ACTION_EAT, ACTION_EXAMINE, ACTION_FACTIONS, ACTION_FIRE, ACTION_FIRE_BURST, ACTION_GRAB, ACTION_HAUL, ACTION_HELP, action_ident(), ACTION_IGNORE_ENEMY, ACTION_INVENTORY, ACTION_ITEMACTION, ACTION_KEYBINDINGS, ACTION_LIST_ITEMS, ACTION_LONGCRAFT, ACTION_LOOK, ACTION_LOOT, ACTION_LUA_CONSOLE, ACTION_LUA_RELOAD, ACTION_MAIN_MENU, ACTION_MAP, ACTION_MEND, ACTION_MESSAGES, ACTION_MISSIONS, ACTION_MORALE, ACTION_MOVE_BACK, ACTION_MOVE_BACK_LEFT, ACTION_MOVE_BACK_RIGHT, ACTION_MOVE_DOWN, ACTION_MOVE_FORTH, ACTION_MOVE_FORTH_LEFT, ACTION_MOVE_FORTH_RIGHT, ACTION_MOVE_LEFT, ACTION_MOVE_RIGHT, ACTION_MOVE_UP, ACTION_MUTATIONS, ACTION_NULL, ACTION_OPEN, ACTION_OPEN_CONSUME, ACTION_OPEN_MOVEMENT, ACTION_OPTIONS, ACTION_ORGANIZE, ACTION_PAUSE, ACTION_PEEK, ACTION_PICK_STYLE, ACTION_PICKUP, ACTION_PICKUP_FEET, ACTION_PL_INFO, ACTION_QUICKLOAD, ACTION_QUICKSAVE, ACTION_READ, ACTION_RECRAFT, ACTION_RELOAD_ITEM, ACTION_RELOAD_TILESET, ACTION_RELOAD_WEAPON, ACTION_RELOAD_WIELDED, ACTION_RESET_MOVE, ACTION_SAFEMODE, ACTION_SAVE, ACTION_SCORES, ACTION_SEC_SELECT, ACTION_SELECT, ACTION_SELECT_DEFAULT_AMMO, ACTION_SELECT_FIRE_MODE, ACTION_SHIFT_E, ACTION_SHIFT_N, ACTION_SHIFT_NE, ACTION_SHIFT_NW, ACTION_SHIFT_S, ACTION_SHIFT_SE, ACTION_SHIFT_SW, ACTION_SHIFT_W, ACTION_SKY, ACTION_SLEEP, ACTION_SMASH, ACTION_SORT_ARMOR, ACTION_SUICIDE, ACTION_TAKE_OFF, ACTION_THROW, ACTION_TIMEOUT, ACTION_TOGGLE_AUTO_FEATURES, ACTION_TOGGLE_AUTO_FORAGING, ACTION_TOGGLE_AUTO_MINING, ACTION_TOGGLE_AUTO_PICKUP, ACTION_TOGGLE_AUTO_PULP_BUTCHER, ACTION_TOGGLE_AUTO_TRAVEL_MODE, ACTION_TOGGLE_AUTOSAFE, ACTION_TOGGLE_CROUCH, ACTION_TOGGLE_DEBUG_MODE, ACTION_TOGGLE_FULLSCREEN, ACTION_TOGGLE_HOUR_TIMER, ACTION_TOGGLE_MAP_MEMORY, ACTION_TOGGLE_PANEL_ADM, ACTION_TOGGLE_PIXEL_MINIMAP, ACTION_TOGGLE_RUN, ACTION_TOGGLE_SAFEMODE, ACTION_TOGGLE_THIEF_MODE, ACTION_UNLOAD, ACTION_USE, ACTION_USE_WIELDED, ACTION_WAIT, ACTION_WEAR, ACTION_WHITELIST_ENEMY, ACTION_WIELD, ACTION_WORLD_MODS, ACTION_ZONES, ACTION_ZOOM_IN, ACTION_ZOOM_OUT, add_msg(), safemode::add_rule(), all_colors, Character::apply_damage(), auto_travel_mode, avatar_action::autoattack(), bio_remote, body_part_head, butcher(), can_action_change_worldstate(), cast_spell(), chat(), check_safe_mode_allowed(), Character::clear_destination(), close(), doors::close_door(), game_menus::inv::common(), game_menus::inv::compare(), construction_menu(), control_vehicle(), Character::controlling_vehicle, player::craft(), create_advanced_inv(), avatar::cycle_move_mode(), dbg, debug_menu::debug(), debug_mode, DebugLog, destination_preview, crafting::disassemble(), Character::dismount(), character_display::disp_info(), avatar::disp_morale(), ui::omap::display(), help::display_help(), display_lighting(), input_context::display_menu(), Messages::display_messages(), item::display_name(), display_radiation(), display_scent(), display_temperature(), display_transparency(), display_vehicle_ai(), display_visibility(), ui::omap::display_visible_weather(), character_funcs::do_pause(), driving_view_offset, drop(), drop_in_direction(), avatar_action::eat(), avatar_action::eat_here(), effect_laserlocked, examine(), faction_manager_ptr, fire(), avatar_action::fire_wielded_weapon(), g, gamemode, get_auto_notes_settings(), get_auto_pickup(), avatar::get_avatar_diary(), input_context::get_coordinates(), get_delta_from_movement_action(), get_distraction_manager(), input_event::get_first_input(), get_help(), input_manager::get_keyname(), get_kill_tracker(), panel_manager::get_manager(), avatar::get_mon_visible(), Character::get_next_auto_move_direction(), options_manager::get_option(), get_option(), get_options(), Character::get_path_avoid(), Character::get_pathfinding_settings(), get_player_input(), input_context::get_raw_input(), get_safemode(), Creature::get_value(), grab(), item::gun_all_modes(), item::gun_cycle_mode(), item::gun_set_mode(), handbrake(), handle_action_menu(), handle_main_menu(), Character::has_active_bionic(), Character::has_active_item(), Character::has_active_mutation(), Character::has_destination(), Character::has_destination_activity(), Creature::has_effect(), Character::has_trait(), haul(), monster::ignoring, Character::in_vehicle, Info, inp_mngr, Character::is_armed(), Character::is_auto_moving(), Character::is_dead_state(), item::is_gun(), item::is_gunmod(), Character::is_mounted(), map::is_outside(), MAP_SHARING::isCompetitive(), MAP_SHARING::isDebugger(), item_action_menu(), itype_radiocontrol, list_items_monsters(), list_missions(), player::long_craft(), look_around(), look_up_action(), loot(), m, m_bad, m_info, m_warning, Main, mark_main_ui_adaptor_resize(), Character::martial_arts_data, avatar_action::mend(), MF_RIDEABLE_MECH, Creature::mod_moves(), mostseen, Character::mounted_creature, avatar_action::move(), player::movecounter, Creature::moves, user_turn::moves_elapsed(), om_direction::name(), monster_visible_info::new_seen_mon, no, NUM_ACTIONS, open(), open_consume_item_menu(), open_movement_mode_menu(), peek(), pickup(), pickup_feet(), Character::place_corpse(), pldrive(), avatar_action::plthrow(), point_east, point_north, point_north_east, point_north_west, point_south, point_south_east, point_south_west, point_west, point_zero, Character::pos(), monster::pos(), Character::posx(), Character::posy(), Character::posz(), press_x(), press_x_if_bound(), Character::primary_weapon(), ranged::prompt_select_default_ammo_for(), query_yn(), quickload(), quicksave(), QUIT_DIED, QUIT_SAVED, QUIT_SUICIDE, QUIT_WATCH, rcdrive(), read(), player::recraft(), avatar_action::reload_item(), cata::reload_lua_code(), reload_tileset(), avatar_action::reload_weapon(), avatar_action::reload_wielded(), remoteveh(), Creature::remove_effect(), avatar::reset_move_mode(), rl_dist(), map::route(), RULE_WHITELISTED, safe_mode, SAFE_MODE_OFF, SAFE_MODE_ON, SAFE_MODE_STOP, safe_mode_warning_logged, save(), options_manager::save(), Character::sees(), SEEX, input_event::sequence, Character::set_destination(), set_safe_mode(), Creature::set_value(), options_manager::cOpt::setNext(), auto_pickup::player_settings::show(), distraction_manager::distraction_manager_gui::show(), safemode::show(), options_manager::show(), panel_manager::show_adm(), show_armor_layers_ui(), show_bionics_ui(), diary::show_diary_ui(), auto_notes::auto_note_settings::show_gui(), cata::show_lua_console(), show_mutations_ui(), show_scores_ui(), sleep, smash(), Character::start_destination_activity(), stats(), string_format(), game_menus::inv::swap_letters(), takeoff(), tile_iso, avatar::toggle_crouch_mode(), toggle_debug_hour_timer(), toggle_fullscreen(), avatar::toggle_map_memory(), toggle_pixel_minimap(), avatar::toggle_run_mode(), trait_PROF_CHURL, trait_SHELL2, tripoint_above, tripoint_below, try_get_left_click_action(), try_get_right_click_action(), calendar::turn, turnssincelastmon, input_event::type, u, avatar_action::unload(), uquit, avatar_action::use_item(), avatar_funcs::use_item(), use_tiles, user_action_counter, map::veh_at(), vertical_move(), player::view_offset, w_terrain, wait(), wear(), avatar_action::wield(), world_generator, point::x, tripoint::x, point::y, tripoint::y, yes, zones_manager(), zoom_in(), and zoom_out().

Referenced by do_turn().

◆ handle_key_blocking_activity()

void game::handle_key_blocking_activity ( )
private

Definition at line 1971 of file game.cpp.

1972{
1974 const std::string action = ctxt.handle_input( 0 );
1975 bool refresh = true;
1976 if( action == "pause" || action == "main_menu" ) {
1978 cancel_activity_query( _( "Confirm:" ) );
1979 }
1980 } else if( action == "player_data" ) {
1982 } else if( action == "messages" ) {
1984 } else if( action == "help" ) {
1986 } else if( action != "HELP_KEYBINDINGS" ) {
1987 refresh = false;
1988 }
1989 if( refresh ) {
1992 }
1993}
bool cancel_activity_query(const std::string &text)
Asks if the player wants to cancel their activity, and if so cancels it.
Definition: game.cpp:1755
const std::string & handle_input()
Handles input and returns the next action in the queue.
Definition: input.cpp:848
bool interruptable_with_kb
Controls whether this activity can be cancelled with 'pause' action.
void refresh()

References _, action, Character::activity, cancel_activity_query(), character_display::disp_info(), help::display_help(), Messages::display_messages(), get_default_mode_input_context(), get_help(), input_context::handle_input(), player_activity::interruptable_with_kb, ui_manager::redraw(), catacurses::refresh(), refresh_display(), and u.

Referenced by process_voluntary_act_interrupt().

◆ handle_mouseview()

bool game::handle_mouseview ( input_context ctxt,
std::string &  action 
)
private

Definition at line 1997 of file game.cpp.

1998{
1999 std::optional<tripoint> liveview_pos;
2000
2001 do {
2002 action = ctxt.handle_input();
2003 if( action == "MOUSE_MOVE" ) {
2004 const std::optional<tripoint> mouse_pos = ctxt.get_coordinates( w_terrain );
2005 if( mouse_pos && ( !liveview_pos || *mouse_pos != *liveview_pos ) ) {
2006 liveview_pos = mouse_pos;
2007 liveview.show( *liveview_pos );
2008 } else if( !mouse_pos ) {
2009 liveview_pos.reset();
2010 liveview.hide();
2011 }
2013 }
2014 } while( action == "MOUSE_MOVE" ); // Freeze animation when moving the mouse
2015
2016 if( action != "TIMEOUT" ) {
2017 // Keyboard event, break out of animation loop
2018 liveview.hide();
2019 return false;
2020 }
2021
2022 // Mouse movement or un-handled key
2023 return true;
2024}
void hide()
Definition: live_view.cpp:33
void show(const tripoint &p)
Definition: live_view.cpp:38

References action, input_context::get_coordinates(), input_context::handle_input(), live_view::hide(), liveview, ui_manager::redraw(), live_view::show(), and w_terrain.

Referenced by get_player_input().

◆ has_gametype()

bool game::has_gametype ( ) const

Definition at line 534 of file game.cpp.

535{
536 return gamemode && gamemode->id() != special_game_type::NONE;
537}

References gamemode, and NONE.

◆ init_autosave()

void game::init_autosave ( )
private

Definition at line 11316 of file game.cpp.

11317{
11319 last_save_timestamp = time( nullptr );
11320}

References last_save_timestamp, moves_since_last_save, and time.

Referenced by load(), and start_game().

◆ inv_map_splice()

item_location game::inv_map_splice ( item_filter  filter,
const std::string &  title,
int  radius = 0,
const std::string &  none_message = "" 
)

Custom-filtered menu for inventory and nearby items and those that within specified radius.

Definition at line 400 of file game_inventory.cpp.

402{
404 title, radius, none_message );
405}
static item_location_filter convert_filter(const item_filter &filter)
static item_location inv_internal(player &u, const inventory_selector_preset &preset, const std::string &title, int radius, const std::string &none_message, const std::string &hint=std::string())
std::string title(holiday current_holiday)
Definition: path_info.cpp:330

References convert_filter(), inv_internal(), PATH_INFO::title(), and u.

◆ invalidate_main_ui_adaptor()

void game::invalidate_main_ui_adaptor ( ) const

◆ is_dangerous_tile()

bool game::is_dangerous_tile ( const tripoint dest_loc) const

Definition at line 8719 of file game.cpp.

8720{
8721 return !( get_dangerous_tile( dest_loc ).empty() );
8722}
std::vector< std::string > get_dangerous_tile(const tripoint &dest_loc) const
Definition: game.cpp:8747

References get_dangerous_tile().

Referenced by walk_move().

◆ is_empty()

bool game::is_empty ( const tripoint p)

Returns true if there is no player, NPC, or monster on the tile and move_cost > 0.

Definition at line 4848 of file game.cpp.

4849{
4850 return ( m.passable( p ) || m.has_flag( "LIQUID", p ) ) &&
4851 critter_at( p ) == nullptr;
4852}

References critter_at(), map::has_flag(), m, and map::passable().

Referenced by grabbed_furn_move(), monmove(), place_player(), and update_stair_monsters().

◆ is_game_over()

bool game::is_game_over ( )
private

Definition at line 2367 of file game.cpp.

2368{
2369 if( uquit == QUIT_WATCH ) {
2370 // deny player movement and dodging
2371 u.moves = 0;
2372 // prevent pain from updating
2373 u.set_pain( 0 );
2374 // prevent dodging
2375 u.dodges_left = 0;
2376 return false;
2377 }
2378 if( uquit == QUIT_DIED ) {
2379 if( u.in_vehicle ) {
2380 m.unboard_vehicle( u.pos() );
2381 }
2382 u.place_corpse();
2383 return true;
2384 }
2385 if( uquit == QUIT_SUICIDE ) {
2386 if( u.in_vehicle ) {
2387 m.unboard_vehicle( u.pos() );
2388 }
2389 return true;
2390 }
2391 if( uquit != QUIT_NO ) {
2392 return true;
2393 }
2394 // is_dead_state() already checks hp_torso && hp_head, no need to for loop it
2395 if( u.is_dead_state() ) {
2396 if( get_option<bool>( "PROMPT_ON_CHARACTER_DEATH" ) &&
2397 !query_yn(
2398 _( "Your character is dead, do you accept this?\n\nSelect Yes to abandon the character to their fate, select No to return to main menu." ) ) ) {
2399 return true;
2400 }
2401
2403 if( get_option<std::string>( "DEATHCAM" ) == "always" ) {
2404 uquit = QUIT_WATCH;
2405 } else if( get_option<std::string>( "DEATHCAM" ) == "ask" ) {
2406 uquit = query_yn( _( "Watch the last moments of your life…?" ) ) ?
2408 } else if( get_option<std::string>( "DEATHCAM" ) == "never" ) {
2409 uquit = QUIT_DIED;
2410 } else {
2411 // Something funky happened here, just die.
2412 dbg( DL::Error ) << "no deathcam option given to options, defaulting to QUIT_DIED";
2413 uquit = QUIT_DIED;
2414 }
2415 return is_game_over();
2416 }
2417 return false;
2418}
int dodges_left
Definition: character.h:569
void set_pain(int npain) override
Sets new intensity of pain an reacts to it.
Definition: character.cpp:791
@ Error
Error (default: enabled).
#define dbg(x)
Definition: game.cpp:200
void deactivate()
Definition: messages.cpp:357

References _, dbg, Messages::deactivate(), Character::dodges_left, Error, Character::in_vehicle, Character::is_dead_state(), is_game_over(), m, Creature::moves, Character::place_corpse(), Character::pos(), query_yn(), QUIT_DIED, QUIT_NO, QUIT_SUICIDE, QUIT_WATCH, Character::set_pain(), u, map::unboard_vehicle(), and uquit.

Referenced by do_turn(), and is_game_over().

◆ is_hostile_nearby()

Creature * game::is_hostile_nearby ( )

Definition at line 3588 of file game.cpp.

3589{
3590 int distance = ( get_option<int>( "SAFEMODEPROXIMITY" ) <= 0 ) ? MAX_VIEW_DISTANCE :
3591 get_option<int>( "SAFEMODEPROXIMITY" );
3592 return is_hostile_within( distance );
3593}
Creature * is_hostile_within(int distance)
Definition: game.cpp:3600

References is_hostile_within(), and MAX_VIEW_DISTANCE.

◆ is_hostile_very_close()

Creature * game::is_hostile_very_close ( )

Definition at line 3595 of file game.cpp.

3596{
3598}
static constexpr int DANGEROUS_PROXIMITY
Definition: game.cpp:202

References DANGEROUS_PROXIMITY, and is_hostile_within().

Referenced by butcher(), and process_voluntary_act_interrupt().

◆ is_hostile_within()

Creature * game::is_hostile_within ( int  distance)
private

Definition at line 3600 of file game.cpp.

3601{
3602 for( auto &critter : u.get_visible_creatures( distance ) ) {
3603 if( u.attitude_to( *critter ) == Creature::A_HOSTILE ) {
3604 return critter;
3605 }
3606 }
3607
3608 return nullptr;
3609}
Attitude attitude_to(const Creature &other) const override
Attitude (of this creature) towards another creature.
std::vector< Creature * > get_visible_creatures(int range) const
Returns all creatures that this player can see and that are in the given range.
@ A_HOSTILE
Definition: creature.h:167

References Creature::A_HOSTILE, Character::attitude_to(), Character::get_visible_creatures(), and u.

Referenced by is_hostile_nearby(), and is_hostile_very_close().

◆ is_in_sunlight()

bool game::is_in_sunlight ( const tripoint p)

Returns true if p is outdoors and it is sunny.

Definition at line 4854 of file game.cpp.

4855{
4856 return weather::is_in_sunlight( m, p, get_weather().weather_id );
4857}
bool is_in_sunlight(const map &m, const tripoint &p, const weather_type_id &weather)
Definition: weather.cpp:1171

References get_weather, weather::is_in_sunlight(), and m.

Referenced by process_artifact().

◆ is_in_viewport()

bool game::is_in_viewport ( const tripoint p,
int  margin = 0 
) const

Definition at line 3234 of file game.cpp.

3235{
3236 const tripoint diff( u.pos() + u.view_offset - p );
3237
3238 return ( std::abs( diff.x ) <= getmaxx( w_terrain ) / 2 - margin ) &&
3239 ( std::abs( diff.y ) <= getmaxy( w_terrain ) / 2 - margin );
3240}

References catacurses::getmaxx(), catacurses::getmaxy(), Character::pos(), u, player::view_offset, w_terrain, tripoint::x, and tripoint::y.

◆ is_sheltered()

bool game::is_sheltered ( const tripoint p)

Returns true if p is indoors, underground, or in a car.

Definition at line 4859 of file game.cpp.

4860{
4861 return weather::is_sheltered( m, p );
4862}
bool is_sheltered(const map &m, const tripoint &p)
Definition: weather.cpp:1162

References weather::is_sheltered(), and m.

◆ is_zones_manager_open()

bool game::is_zones_manager_open ( ) const

Definition at line 6054 of file game.cpp.

6055{
6056 return zones_manager_open;
6057}
bool zones_manager_open
Is Zone manager open or not - changes graphics of some zone tiles.
Definition: game.h:1052

References zones_manager_open.

◆ item_action_menu()

void game::item_action_menu ( )
private

Definition at line 231 of file item_action.cpp.

232{
233 const auto &gen = item_action_generator::generator();
234 const action_map &item_actions = gen.get_item_action_map();
235
236 // HACK: A bit of a hack for now. If more pseudos get implemented, this should be un-hacked
237 std::vector<item *> pseudos;
238 item toolset( "toolset", calendar::turn );
239 if( u.has_active_bionic( bio_tools ) ) {
240 pseudos.push_back( &toolset );
241 }
242 item bio_claws_item( static_cast<std::string>( bio_claws_weapon ), calendar::turn );
243 if( u.has_active_bionic( bio_claws ) ) {
244 pseudos.push_back( &bio_claws_item );
245 }
246
247 item_action_map iactions = gen.map_actions_to_items( u, pseudos );
248 if( iactions.empty() ) {
249 popup( _( "You don't have any items with registered uses" ) );
250 }
251
252 uilist kmenu;
253 kmenu.text = _( "Execute which action?" );
254 kmenu.input_category = "ITEM_ACTIONS";
255 input_context ctxt( "ITEM_ACTIONS" );
256 for( const auto &id : item_actions ) {
257 ctxt.register_action( id.first, id.second.name );
258 kmenu.additional_actions.emplace_back( id.first, id.second.name );
259 }
260 actmenu_cb callback( item_actions );
261 kmenu.callback = &callback;
262 int num = 0;
263
264 const auto assigned_action = [&iactions]( const item_action_id & action ) {
265 return iactions.find( action ) != iactions.end();
266 };
267
268 std::vector<std::tuple<item_action_id, std::string, std::string>> menu_items;
269 // Sorts menu items by action.
270 using Iter = decltype( menu_items )::iterator;
271 const auto sort_menu = []( Iter from, Iter to ) {
272 std::sort( from, to, []( const std::tuple<item_action_id, std::string, std::string> &lhs,
273 const std::tuple<item_action_id, std::string, std::string> &rhs ) {
274 return std::get<1>( lhs ).compare( std::get<1>( rhs ) ) < 0;
275 } );
276 };
277 // Add mapped actions to the menu vector.
278 std::transform( iactions.begin(), iactions.end(), std::back_inserter( menu_items ),
279 []( const std::pair<item_action_id, item *> &elem ) {
280 std::string ss = elem.second->display_name();
281 if( elem.second->ammo_required() ) {
282 ss += string_format( " (%d/%d)", elem.second->ammo_required(), elem.second->ammo_remaining() );
283 }
284
285 const auto method = elem.second->get_use( elem.first );
286 if( method ) {
287 return std::make_tuple( method->get_type(), method->get_name(), ss );
288 } else {
289 return std::make_tuple( errstring, std::string( "NO USE FUNCTION" ), ss );
290 }
291 } );
292 // Sort mapped actions.
293 sort_menu( menu_items.begin(), menu_items.end() );
294 // Add unmapped but binded actions to the menu vector.
295 for( const auto &elem : item_actions ) {
296 if( key_bound_to( ctxt, elem.first ) != '\0' && !assigned_action( elem.first ) ) {
297 menu_items.emplace_back( elem.first, gen.get_action_name( elem.first ), "-" );
298 }
299 }
300 // Sort unmapped actions.
301 auto iter = menu_items.begin();
302 std::advance( iter, iactions.size() );
303 sort_menu( iter, menu_items.end() );
304 // Determine max lengths, to print the menu nicely.
305 std::pair<int, int> max_len;
306 for( const auto &elem : menu_items ) {
307 max_len.first = std::max( max_len.first, utf8_width( std::get<1>( elem ), true ) );
308 max_len.second = std::max( max_len.second, utf8_width( std::get<2>( elem ), true ) );
309 }
310 // Fill the menu.
311 for( const auto &elem : menu_items ) {
312 std::string ss;
313 ss += std::get<1>( elem );
314 ss += std::string( max_len.first - utf8_width( std::get<1>( elem ), true ), ' ' );
315 ss += std::string( 4, ' ' );
316
317 ss += std::get<2>( elem );
318 ss += std::string( max_len.second - utf8_width( std::get<2>( elem ), true ), ' ' );
319
320 const char bind = key_bound_to( ctxt, std::get<0>( elem ) );
321 const bool enabled = assigned_action( std::get<0>( elem ) );
322
323 kmenu.addentry( num, enabled, bind, ss );
324 num++;
325 }
326
327 kmenu.query();
328 if( kmenu.ret < 0 || kmenu.ret >= static_cast<int>( iactions.size() ) ) {
329 return;
330 }
331
332 const item_action_id action = std::get<0>( menu_items[kmenu.ret] );
333 item *it = iactions[action];
334
335 u.invoke_item( it, action );
336
337 u.inv.restack( u );
338 u.inv.unsort();
339}
inventory inv
Definition: character.h:1579
bool invoke_item(item *, const tripoint &pt) override
Asks how to use the item (if it has more than one use_method) and uses it.
Definition: avatar.cpp:1257
void restack(player &p)
Definition: inventory.cpp:400
void unsort()
Definition: inventory.cpp:228
static item_action_generator & generator()
Definition: item_action.h:32
std::string input_category
Definition: ui.h:325
std::vector< std::pair< std::string, translation > > additional_actions
Definition: ui.h:326
static char key_bound_to(const input_context &ctxt, const item_action_id &act)
Definition: item_action.cpp:47
static const bionic_id bio_claws("bio_claws")
static const bionic_id bio_tools("bio_tools")
static const bionic_id bio_claws_weapon("bio_claws_weapon")
std::string item_action_id
Definition: item_action.h:16
std::map< item_action_id, item_action > action_map
Definition: item_action.h:18
std::map< item_action_id, item * > item_action_map
Definition: item_action.h:17

References _, action, uilist::additional_actions, bio_claws, bio_claws_weapon, bio_tools, uilist::callback, item_action_generator::generator(), Character::has_active_bionic(), uilist::input_category, num, popup(), input_context::register_action(), second, uilist::text, iexamine::transform(), calendar::turn, and u.

Referenced by handle_action().

◆ knockback() [1/2]

void game::knockback ( const tripoint s,
const tripoint t,
int  force,
int  stun,
int  dam_mult,
Creature source 
)

Definition at line 4253 of file game.cpp.

4255{
4256 std::vector<tripoint> traj;
4257 traj.clear();
4258 traj = line_to( s, t, 0, 0 );
4259 traj.insert( traj.begin(), s ); // how annoying, line_to() doesn't include the originating point!
4260 traj = continue_line( traj, force );
4261 traj.insert( traj.begin(), t ); // how annoying, continue_line() doesn't either!
4262
4263 knockback( traj, stun, dam_mult, source );
4264}
std::vector< coords::coord_point< Point, Origin, Scale > > line_to(const coords::coord_point< Point, Origin, Scale > &loc1, const coords::coord_point< Point, Origin, Scale > &loc2)
Definition: coordinates.h:548
std::vector< tripoint > continue_line(const std::vector< tripoint > &line, const int distance)
Definition: line.cpp:408

References continue_line(), knockback(), and line_to().

Referenced by forced_door_closing(), and knockback().

◆ knockback() [2/2]

void game::knockback ( std::vector< tripoint > &  traj,
int  stun,
int  dam_mult,
Creature source = nullptr 
)

Definition at line 4270 of file game.cpp.

4272{
4273 // TODO: make the force parameter actually do something.
4274 // the header file says higher force causes more damage.
4275 // perhaps that is what it should do?
4276
4277 // TODO: refactor this so it's not copy/pasted 3 times
4278 tripoint tp = traj.front();
4279 if( !critter_at( tp ) ) {
4280 debugmsg( _( "Nothing at (%d,%d,%d) to knockback!" ), tp.x, tp.y, tp.z );
4281 return;
4282 }
4283 std::size_t force_remaining = traj.size();
4284 if( monster *const targ = critter_at<monster>( tp, true ) ) {
4285 tripoint start_pos = targ->pos();
4286
4287 if( stun > 0 ) {
4288 targ->add_effect( effect_stunned, 1_turns * stun );
4289 add_msg( _( "%s was stunned!" ), targ->name() );
4290 }
4291 for( size_t i = 1; i < traj.size(); i++ ) {
4292 if( m.impassable( traj[i].xy() ) || m.obstructed_by_vehicle_rotation( tp, traj[i] ) ) {
4293 targ->setpos( traj[i - 1] );
4294 force_remaining = traj.size() - i;
4295 if( stun != 0 ) {
4296 targ->add_effect( effect_stunned, 1_turns * force_remaining );
4297 add_msg( _( "%s was stunned!" ), targ->name() );
4298 add_msg( _( "%s slammed into an obstacle!" ), targ->name() );
4299 targ->apply_damage( source, bodypart_id( "torso" ), dam_mult * force_remaining );
4300 targ->check_dead_state();
4301 }
4302 m.bash( traj[i], 2 * dam_mult * force_remaining );
4303 break;
4304 } else if( critter_at( traj[i] ) ) {
4305 targ->setpos( traj[i - 1] );
4306 force_remaining = traj.size() - i;
4307 if( stun != 0 ) {
4308 targ->add_effect( effect_stunned, 1_turns * force_remaining );
4309 add_msg( _( "%s was stunned!" ), targ->name() );
4310 }
4311 traj.erase( traj.begin(), traj.begin() + i );
4312 if( critter_at<monster>( traj.front() ) ) {
4313 add_msg( _( "%s collided with something else and sent it flying!" ),
4314 targ->name() );
4315 } else if( npc *const guy = critter_at<npc>( traj.front() ) ) {
4316 if( guy->male ) {
4317 add_msg( _( "%s collided with someone else and sent him flying!" ),
4318 targ->name() );
4319 } else {
4320 add_msg( _( "%s collided with someone else and sent her flying!" ),
4321 targ->name() );
4322 }
4323 } else if( u.pos() == traj.front() ) {
4324 add_msg( m_bad, _( "%s collided with you and sent you flying!" ), targ->name() );
4325 }
4326 knockback( traj, stun, dam_mult, source );
4327 break;
4328 }
4329 targ->setpos( traj[i] );
4330 if( m.has_flag( "LIQUID", targ->pos() ) && targ->can_drown() && !targ->is_dead() ) {
4331 targ->die( source );
4332 if( u.sees( *targ ) ) {
4333 add_msg( _( "The %s drowns!" ), targ->name() );
4334 }
4335 }
4336 if( !m.has_flag( "LIQUID", targ->pos() ) && targ->has_flag( MF_AQUATIC ) &&
4337 !targ->is_dead() ) {
4338 targ->die( source );
4339 if( u.sees( *targ ) ) {
4340 add_msg( _( "The %s flops around and dies!" ), targ->name() );
4341 }
4342 }
4343 tp = traj[i];
4344 if( start_pos != targ->pos() ) {
4345 map &here = get_map();
4346 here.creature_on_trap( *targ );
4347 }
4348 }
4349 } else if( npc *const targ = critter_at<npc>( tp ) ) {
4350 tripoint start_pos = targ->pos();
4351
4352 if( stun > 0 ) {
4353 targ->add_effect( effect_stunned, 1_turns * stun );
4354 add_msg( _( "%s was stunned!" ), targ->name );
4355 }
4356 for( size_t i = 1; i < traj.size(); i++ ) {
4357 if( m.impassable( traj[i].xy() ) ||
4358 m.obstructed_by_vehicle_rotation( tp, traj[i] ) ) { // oops, we hit a wall!
4359 targ->setpos( traj[i - 1] );
4360 force_remaining = traj.size() - i;
4361 if( stun != 0 ) {
4362 targ->add_effect( effect_stunned, 1_turns * force_remaining );
4363 if( targ->has_effect( effect_stunned ) ) {
4364 add_msg( _( "%s was stunned!" ), targ->name );
4365 }
4366
4367 std::array<bodypart_id, 8> bps = {{
4368 bodypart_id( "head" ),
4369 bodypart_id( "arm_l" ), bodypart_id( "arm_r" ),
4370 bodypart_id( "hand_l" ), bodypart_id( "hand_r" ),
4371 bodypart_id( "torso" ),
4372 bodypart_id( "leg_l" ), bodypart_id( "leg_r" )
4373 }
4374 };
4375 for( const bodypart_id &bp : bps ) {
4376 if( one_in( 2 ) ) {
4377 targ->deal_damage( source, bp, damage_instance( DT_BASH, force_remaining * dam_mult ) );
4378 }
4379 }
4380 targ->check_dead_state();
4381 }
4382 m.bash( traj[i], 2 * dam_mult * force_remaining );
4383 break;
4384 } else if( critter_at( traj[i] ) ) {
4385 targ->setpos( traj[i - 1] );
4386 force_remaining = traj.size() - i;
4387 if( stun != 0 ) {
4388 add_msg( _( "%s was stunned!" ), targ->name );
4389 targ->add_effect( effect_stunned, 1_turns * force_remaining );
4390 }
4391 traj.erase( traj.begin(), traj.begin() + i );
4392 const tripoint &traj_front = traj.front();
4393 if( critter_at<monster>( traj_front ) ) {
4394 add_msg( _( "%s collided with something else and sent it flying!" ),
4395 targ->name );
4396 } else if( npc *const guy = critter_at<npc>( traj_front ) ) {
4397 if( guy->male ) {
4398 add_msg( _( "%s collided with someone else and sent him flying!" ),
4399 targ->name );
4400 } else {
4401 add_msg( _( "%s collided with someone else and sent her flying!" ),
4402 targ->name );
4403 }
4404 } else if( u.posx() == traj_front.x && u.posy() == traj_front.y &&
4406 ( u.footwear_factor() == .5 && one_in( 2 ) ) ) ) ) {
4407 add_msg( _( "%s collided with you, and barely dislodges your tentacles!" ), targ->name );
4408 } else if( u.posx() == traj_front.x && u.posy() == traj_front.y ) {
4409 add_msg( m_bad, _( "%s collided with you and sent you flying!" ), targ->name );
4410 }
4411 knockback( traj, stun, dam_mult, source );
4412 break;
4413 }
4414 targ->setpos( traj[i] );
4415 tp = traj[i];
4416
4417 if( start_pos != targ->pos() ) {
4418 map &here = get_map();
4419 here.creature_on_trap( *targ );
4420 }
4421 }
4422 } else if( u.pos() == tp ) {
4423 tripoint start_pos = u.pos();
4424
4425 if( stun > 0 ) {
4426 u.add_effect( effect_stunned, 1_turns * stun );
4427 add_msg( m_bad, vgettext( "You were stunned for %d turn!",
4428 "You were stunned for %d turns!",
4429 stun ),
4430 stun );
4431 }
4432 for( size_t i = 1; i < traj.size(); i++ ) {
4433 if( m.impassable( traj[i] ) ||
4434 m.obstructed_by_vehicle_rotation( tp, traj[i] ) ) { // oops, we hit a wall!
4435 u.setpos( traj[i - 1] );
4436 force_remaining = traj.size() - i;
4437 if( stun != 0 ) {
4438 if( u.has_effect( effect_stunned ) ) {
4439 add_msg( m_bad, vgettext( "You were stunned AGAIN for %d turn!",
4440 "You were stunned AGAIN for %d turns!",
4441 force_remaining ),
4442 force_remaining );
4443 } else {
4444 add_msg( m_bad, vgettext( "You were stunned for %d turn!",
4445 "You were stunned for %d turns!",
4446 force_remaining ),
4447 force_remaining );
4448 }
4449 u.add_effect( effect_stunned, 1_turns * force_remaining );
4450 std::array<bodypart_id, 8> bps = {{
4451 bodypart_id( "head" ),
4452 bodypart_id( "arm_l" ), bodypart_id( "arm_r" ),
4453 bodypart_id( "hand_l" ), bodypart_id( "hand_r" ),
4454 bodypart_id( "torso" ),
4455 bodypart_id( "leg_l" ), bodypart_id( "leg_r" )
4456 }
4457 };
4458 for( const bodypart_id &bp : bps ) {
4459 if( one_in( 2 ) ) {
4460 u.deal_damage( source, bp, damage_instance( DT_BASH, force_remaining * dam_mult ) );
4461 }
4462 }
4464 }
4465 m.bash( traj[i], 2 * dam_mult * force_remaining );
4466 break;
4467 } else if( critter_at( traj[i] ) ) {
4468 u.setpos( traj[i - 1] );
4469 force_remaining = traj.size() - i;
4470 if( stun != 0 ) {
4471 if( u.has_effect( effect_stunned ) ) {
4472 add_msg( m_bad, vgettext( "You were stunned AGAIN for %d turn!",
4473 "You were stunned AGAIN for %d turns!",
4474 force_remaining ),
4475 force_remaining );
4476 } else {
4477 add_msg( m_bad, vgettext( "You were stunned for %d turn!",
4478 "You were stunned for %d turns!",
4479 force_remaining ),
4480 force_remaining );
4481 }
4482 u.add_effect( effect_stunned, 1_turns * force_remaining );
4483 }
4484 traj.erase( traj.begin(), traj.begin() + i );
4485 if( critter_at<monster>( traj.front() ) ) {
4486 add_msg( _( "You collided with something and sent it flying!" ) );
4487 } else if( npc *const guy = critter_at<npc>( traj.front() ) ) {
4488 if( guy->male ) {
4489 add_msg( _( "You collided with someone and sent him flying!" ) );
4490 } else {
4491 add_msg( _( "You collided with someone and sent her flying!" ) );
4492 }
4493 }
4494 knockback( traj, stun, dam_mult, source );
4495 break;
4496 }
4497 if( m.has_flag( "LIQUID", u.pos() ) && force_remaining == 0 ) {
4498 avatar_action::swim( m, u, u.pos() );
4499 } else {
4500 u.setpos( traj[i] );
4501 }
4502 tp = traj[i];
4503
4504 if( start_pos != u.pos() ) {
4505 map &here = get_map();
4506 here.creature_on_trap( u );
4507 }
4508 }
4509 }
4510}
double footwear_factor() const
Returns 1 if the player is wearing something on both feet, .5 if on one, and 0 if on neither.
Definition: character.cpp:8942
dealt_damage_instance deal_damage(Creature *source, bodypart_id bp, const damage_instance &d) override
Calls Creature::deal_damage and handles damaged effects (waking up, etc.)
Definition: character.cpp:8466
void add_effect(const effect &eff, bool force=false, bool deferred=false)
Definition: creature.cpp:1008
@ DT_BASH
Definition: damage.h:24
static const trait_id trait_LEG_TENT_BRACE("LEG_TENT_BRACE")
static const efftype_id effect_stunned("stunned")
@ MF_AQUATIC
Definition: mtype.h:89
void swim(map &m, avatar &you, const tripoint &p)
Handles swimming by the player.
const char * vgettext(const char *msgid, const char *msgid_plural, size_t n)

References _, Creature::add_effect(), add_msg(), map::bash(), Creature::check_dead_state(), critter_at(), Character::deal_damage(), debugmsg, DT_BASH, effect_stunned, Character::footwear_factor(), get_map, Creature::has_effect(), map::has_flag(), Character::has_trait(), anonymous_namespace{iexamine_elevator.cpp}::elevator::here(), map::impassable(), knockback(), m, m_bad, MF_AQUATIC, map::obstructed_by_vehicle_rotation(), one_in(), Character::pos(), Character::posx(), Character::posy(), Character::sees(), Character::setpos(), avatar_action::swim(), trait_LEG_TENT_BRACE, u, vgettext(), tripoint::x, tripoint::y, and tripoint::z.

◆ light_level()

unsigned char game::light_level ( int  zlev) const

Returns coarse number-of-squares of visibility at the current light level.

Used by monster and NPC AI.

Definition at line 3567 of file game.cpp.

3568{
3569 const float light = natural_light_level( zlev );
3570 return LIGHT_RANGE( light );
3571}
float natural_light_level(int zlev) const
Definition: game.cpp:3507
#define LIGHT_RANGE(b)
Definition: lightmap.h:41

References light, LIGHT_RANGE, and natural_light_level().

Referenced by calc_driving_offset(), and update_overmap_seen().

◆ list_active_saves()

std::vector< std::string > game::list_active_saves ( )

Returns a list of currently active character saves.

Definition at line 2774 of file game.cpp.

2775{
2776 std::vector<std::string> saves;
2777 for( auto &worldsave : world_generator->active_world->world_saves ) {
2778 saves.push_back( worldsave.decoded_name() );
2779 }
2780 return saves;
2781}

References world_generator.

Referenced by cleanup_at_end().

◆ list_items()

game::vmenu_ret game::list_items ( const std::vector< map_item_stack > &  item_list)
private

Definition at line 7297 of file game.cpp.

7298{
7299 std::vector<map_item_stack> ground_items = item_list;
7300 int iInfoHeight = 0;
7301 int iMaxRows = 0;
7302 int width = 0;
7303 int max_name_width = 0;
7304
7305 //find max length of item name and resize window width
7306 for( const map_item_stack &cur_item : ground_items ) {
7307 const int item_len = utf8_width( remove_color_tags( cur_item.example->display_name() ) ) + 15;
7308 if( item_len > max_name_width ) {
7309 max_name_width = item_len;
7310 }
7311 }
7312
7313 tripoint active_pos;
7314 map_item_stack *activeItem = nullptr;
7315
7316 catacurses::window w_items;
7317 catacurses::window w_items_border;
7318 catacurses::window w_item_info;
7319
7320 ui_adaptor ui;
7321 ui.on_screen_resize( [&]( ui_adaptor & ui ) {
7322 iInfoHeight = std::min( 25, TERMY / 2 );
7323 iMaxRows = TERMY - iInfoHeight - 2;
7324
7325 width = clamp( max_name_width, 45, TERMX / 3 );
7326
7327 const int offsetX = TERMX - width;
7328
7329 w_items = catacurses::newwin( TERMY - 2 - iInfoHeight,
7330 width - 2, point( offsetX + 1, 1 ) );
7331 w_items_border = catacurses::newwin( TERMY - iInfoHeight,
7332 width, point( offsetX, 0 ) );
7333 w_item_info = catacurses::newwin( iInfoHeight, width,
7334 point( offsetX, TERMY - iInfoHeight ) );
7335
7336 if( activeItem ) {
7337 centerlistview( active_pos, width );
7338 }
7339
7340 ui.position( point( offsetX, 0 ), point( width, TERMY ) );
7341 } );
7342 ui.mark_resize();
7343
7344 // use previously selected sorting method
7345 bool sort_radius = uistate.list_item_sort != 2;
7346 bool addcategory = !sort_radius;
7347
7348 // reload filter/priority settings on the first invocation, if they were active
7349 if( !uistate.list_item_init ) {
7352 }
7355 }
7358 }
7359 uistate.list_item_init = true;
7360 }
7361
7362 //this stores only those items that match our filter
7363 std::vector<map_item_stack> filtered_items =
7364 !sFilter.empty() ? filter_item_stacks( ground_items, sFilter ) : ground_items;
7365 int highPEnd = list_filter_high_priority( filtered_items, list_item_upvote );
7366 int lowPStart = list_filter_low_priority( filtered_items, highPEnd, list_item_downvote );
7367 int iItemNum = ground_items.size();
7368
7369 const tripoint stored_view_offset = u.view_offset;
7370
7372
7373 int iActive = 0; // Item index that we're looking at
7374 bool refilter = true;
7375 int page_num = 0;
7376 int iCatSortNum = 0;
7377 int iScrollPos = 0;
7378 std::map<int, std::string> mSortCategory;
7379
7380 std::string action;
7381 input_context ctxt( "LIST_ITEMS" );
7382 ctxt.register_action( "UP", to_translation( "Move cursor up" ) );
7383 ctxt.register_action( "DOWN", to_translation( "Move cursor down" ) );
7384 ctxt.register_action( "LEFT", to_translation( "Previous item" ) );
7385 ctxt.register_action( "RIGHT", to_translation( "Next item" ) );
7386 ctxt.register_action( "PAGE_DOWN" );
7387 ctxt.register_action( "PAGE_UP" );
7388 ctxt.register_action( "NEXT_TAB" );
7389 ctxt.register_action( "PREV_TAB" );
7390 ctxt.register_action( "HELP_KEYBINDINGS" );
7391 ctxt.register_action( "QUIT" );
7392 ctxt.register_action( "FILTER" );
7393 ctxt.register_action( "RESET_FILTER" );
7394 ctxt.register_action( "EXAMINE" );
7395 ctxt.register_action( "COMPARE" );
7396 ctxt.register_action( "PRIORITY_INCREASE" );
7397 ctxt.register_action( "PRIORITY_DECREASE" );
7398 ctxt.register_action( "SORT" );
7399 ctxt.register_action( "TRAVEL_TO" );
7400
7401 std::optional<item_filter_type> filter_type;
7402
7403 ui.on_redraw( [&]( const ui_adaptor & ) {
7404 reset_item_list_state( w_items_border, iInfoHeight, sort_radius );
7405
7406 if( ground_items.empty() ) {
7407 wnoutrefresh( w_items_border );
7408 mvwprintz( w_items, point( 2, 10 ), c_white, _( "You don't see any items around you!" ) );
7409 } else {
7410 int iStartPos = 0;
7411 werase( w_items );
7412 calcStartPos( iStartPos, iActive, iMaxRows, iItemNum );
7413 int iNum = 0;
7414 bool high = false;
7415 bool low = false;
7416 int index = 0;
7417 int iCatSortOffset = 0;
7418
7419 for( int i = 0; i < iStartPos; i++ ) {
7420 if( !mSortCategory[i].empty() ) {
7421 iNum++;
7422 }
7423 }
7424 for( auto iter = filtered_items.begin(); iter != filtered_items.end(); ++index ) {
7425 if( highPEnd > 0 && index < highPEnd + iCatSortOffset ) {
7426 high = true;
7427 low = false;
7428 } else if( index >= lowPStart + iCatSortOffset ) {
7429 high = false;
7430 low = true;
7431 } else {
7432 high = false;
7433 low = false;
7434 }
7435
7436 if( iNum >= iStartPos && iNum < iStartPos + ( iMaxRows > iItemNum ? iItemNum : iMaxRows ) ) {
7437 int iThisPage = 0;
7438 if( !mSortCategory[iNum].empty() ) {
7439 iCatSortOffset++;
7440 mvwprintz( w_items, point( 1, iNum - iStartPos ), c_magenta, mSortCategory[iNum] );
7441 } else {
7442 if( iNum == iActive ) {
7443 iThisPage = page_num;
7444 }
7445 std::string sText;
7446 if( iter->vIG.size() > 1 ) {
7447 sText += string_format( "[%d/%d] (%d) ", iThisPage + 1, iter->vIG.size(), iter->totalcount );
7448 }
7449 sText += iter->example->tname();
7450 if( iter->vIG[iThisPage].count > 1 ) {
7451 sText += string_format( "[%d]", iter->vIG[iThisPage].count );
7452 }
7453
7454 nc_color col = c_light_green;
7455 if( iNum != iActive ) {
7456 if( high ) {
7457 col = c_yellow;
7458 } else if( low ) {
7459 col = c_red;
7460 } else {
7461 col = iter->example->color_in_inventory();
7462 }
7463 }
7464 trim_and_print( w_items, point( 1, iNum - iStartPos ), width - 9, col, sText );
7465 const int numw = iItemNum > 9 ? 2 : 1;
7466 const int x = iter->vIG[iThisPage].pos.x;
7467 const int y = iter->vIG[iThisPage].pos.y;
7468 mvwprintz( w_items, point( width - 6 - numw, iNum - iStartPos ),
7469 iNum == iActive ? c_light_green : c_light_gray,
7470 "%*d %s", numw, rl_dist( point_zero, point( x, y ) ),
7472 ++iter;
7473 }
7474 } else {
7475 ++iter;
7476 }
7477 iNum++;
7478 }
7479 iNum = 0;
7480 for( int i = 0; i < iActive; i++ ) {
7481 if( !mSortCategory[i].empty() ) {
7482 iNum++;
7483 }
7484 }
7485 mvwprintz( w_items_border, point( ( width - 9 ) / 2 + ( iItemNum > 9 ? 0 : 1 ), 0 ),
7486 c_light_green, " %*d", iItemNum > 9 ? 2 : 1, iItemNum > 0 ? iActive - iNum + 1 : 0 );
7487 wprintz( w_items_border, c_white, " / %*d ", iItemNum > 9 ? 2 : 1, iItemNum - iCatSortNum );
7488 werase( w_item_info );
7489
7490 if( iItemNum > 0 && activeItem ) {
7491 item_location loc( map_cursor( u.pos() + activeItem->example_item_pos ),
7492 const_cast<item *>( activeItem->example ) );
7494 std::vector<iteminfo> this_item = activeItem->example->info( temperature );
7495 std::vector<iteminfo> item_info_dummy;
7496
7497 item_info_data dummy( "", "", this_item, item_info_dummy, iScrollPos );
7498 dummy.without_getch = true;
7499 dummy.without_border = true;
7500
7501 draw_item_info( w_item_info, dummy );
7502 }
7503 draw_scrollbar( w_items_border, iActive, iMaxRows, iItemNum, point_south );
7504 wnoutrefresh( w_items_border );
7505 }
7506
7507 const bool bDrawLeft = ground_items.empty() || filtered_items.empty() || !activeItem || filter_type;
7508 draw_custom_border( w_item_info, bDrawLeft, true, true, true, LINE_XXXO, LINE_XOXX, true, true );
7509
7510 if( iItemNum > 0 && activeItem ) {
7511 // print info window title: < item name >
7512 mvwprintw( w_item_info, point( 2, 0 ), "< " );
7513 trim_and_print( w_item_info, point( 4, 0 ), width - 8, activeItem->example->color_in_inventory(),
7514 activeItem->example->display_name() );
7515 wprintw( w_item_info, " >" );
7516 }
7517
7518 wnoutrefresh( w_items );
7519 wnoutrefresh( w_item_info );
7520
7521 if( filter_type ) {
7522 draw_item_filter_rules( w_item_info, 0, iInfoHeight - 1, filter_type.value() );
7523 }
7524 } );
7525
7526 std::optional<tripoint> trail_start;
7527 std::optional<tripoint> trail_end;
7528 bool trail_end_x = false;
7529 shared_ptr_fast<draw_callback_t> trail_cb = create_trail_callback( trail_start, trail_end,
7530 trail_end_x );
7531 add_draw_callback( trail_cb );
7532
7533 do {
7534 if( action == "COMPARE" && activeItem ) {
7535 game_menus::inv::compare( u, active_pos );
7536 } else if( action == "FILTER" ) {
7537 filter_type = item_filter_type::FILTER;
7538 ui.invalidate_ui();
7540 .title( _( "Filter:" ) )
7541 .width( 55 )
7542 .description( _( "UP: history, CTRL-U: clear line, ESC: abort, ENTER: save" ) )
7543 .identifier( "item_filter" )
7544 .max_length( 256 )
7545 .edit( sFilter );
7546 refilter = true;
7547 addcategory = !sort_radius;
7549 filter_type = std::nullopt;
7550 } else if( action == "RESET_FILTER" ) {
7551 sFilter.clear();
7552 filtered_items = ground_items;
7553 refilter = true;
7555 addcategory = !sort_radius;
7556 } else if( action == "EXAMINE" && !filtered_items.empty() && activeItem ) {
7557 std::vector<iteminfo> dummy;
7558 const item *example_item = activeItem->example;
7559 // TODO: const_item_location
7560 item_location loc = item_location( u, const_cast<item *>( example_item ) );
7562 std::vector<iteminfo> this_item = example_item->info( temperature );
7563
7564 item_info_data info_data( example_item->tname(), example_item->type_name(), this_item, dummy );
7565 info_data.handle_scrolling = true;
7566
7568 return catacurses::newwin( TERMY, width - 5, point_zero );
7569 }, info_data );
7570 } else if( action == "PRIORITY_INCREASE" ) {
7571 filter_type = item_filter_type::HIGH_PRIORITY;
7572 ui.invalidate_ui();
7574 .title( _( "High Priority:" ) )
7575 .width( 55 )
7577 .description( _( "UP: history, CTRL-U clear line, ESC: abort, ENTER: save" ) )
7578 .identifier( "list_item_priority" )
7579 .max_length( 256 )
7580 .query_string();
7581 refilter = true;
7582 addcategory = !sort_radius;
7584 filter_type = std::nullopt;
7585 } else if( action == "PRIORITY_DECREASE" ) {
7586 filter_type = item_filter_type::LOW_PRIORITY;
7587 ui.invalidate_ui();
7589 .title( _( "Low Priority:" ) )
7590 .width( 55 )
7592 .description( _( "UP: history, CTRL-U clear line, ESC: abort, ENTER: save" ) )
7593 .identifier( "list_item_downvote" )
7594 .max_length( 256 )
7595 .query_string();
7596 refilter = true;
7597 addcategory = !sort_radius;
7599 filter_type = std::nullopt;
7600 } else if( action == "SORT" ) {
7601 if( sort_radius ) {
7602 sort_radius = false;
7603 addcategory = true;
7604 uistate.list_item_sort = 2; // list is sorted by category
7605 } else {
7606 sort_radius = true;
7607 uistate.list_item_sort = 1; // list is sorted by distance
7608 }
7609 highPEnd = -1;
7610 lowPStart = -1;
7611 iCatSortNum = 0;
7612
7613 mSortCategory.clear();
7614 refilter = true;
7615 } else if( action == "TRAVEL_TO" && activeItem ) {
7616 if( !u.sees( u.pos() + active_pos ) ) {
7617 add_msg( _( "You can't see that destination." ) );
7618 }
7619 auto route = m.route( u.pos(), u.pos() + active_pos, u.get_pathfinding_settings(),
7620 u.get_path_avoid() );
7621 if( route.size() > 1 ) {
7622 route.pop_back();
7623 u.set_destination( route );
7624 break;
7625 } else {
7626 add_msg( m_info, _( "You can't travel there." ) );
7627 }
7628 }
7629 if( uistate.list_item_sort == 1 ) {
7630 ground_items = item_list;
7631 } else if( uistate.list_item_sort == 2 ) {
7632 std::sort( ground_items.begin(), ground_items.end(), map_item_stack::map_item_stack_sort );
7633 }
7634
7635 if( refilter ) {
7636 refilter = false;
7637 filtered_items = filter_item_stacks( ground_items, sFilter );
7638 highPEnd = list_filter_high_priority( filtered_items, list_item_upvote );
7639 lowPStart = list_filter_low_priority( filtered_items, highPEnd, list_item_downvote );
7640 iActive = 0;
7641 page_num = 0;
7642 iItemNum = filtered_items.size();
7643 }
7644
7645 if( addcategory ) {
7646 addcategory = false;
7647 iCatSortNum = 0;
7648 mSortCategory.clear();
7649 if( highPEnd > 0 ) {
7650 mSortCategory[0] = _( "HIGH PRIORITY" );
7651 iCatSortNum++;
7652 }
7653 std::string last_cat_name;
7654 for( int i = std::max( 0, highPEnd );
7655 i < std::min( lowPStart, static_cast<int>( filtered_items.size() ) ); i++ ) {
7656 const std::string &cat_name = filtered_items[i].example->get_category().name();
7657 if( cat_name != last_cat_name ) {
7658 mSortCategory[i + iCatSortNum++] = cat_name;
7659 last_cat_name = cat_name;
7660 }
7661 }
7662 if( lowPStart < static_cast<int>( filtered_items.size() ) ) {
7663 mSortCategory[lowPStart + iCatSortNum++] = _( "LOW PRIORITY" );
7664 }
7665 if( !mSortCategory[0].empty() ) {
7666 iActive++;
7667 }
7668 iItemNum = static_cast<int>( filtered_items.size() ) + iCatSortNum;
7669 }
7670
7671 if( action == "UP" ) {
7672 do {
7673 iActive--;
7674
7675 } while( !mSortCategory[iActive].empty() );
7676 iScrollPos = 0;
7677 page_num = 0;
7678 if( iActive < 0 ) {
7679 iActive = iItemNum - 1;
7680 }
7681 } else if( action == "DOWN" ) {
7682 do {
7683 iActive++;
7684
7685 } while( !mSortCategory[iActive].empty() );
7686 iScrollPos = 0;
7687 page_num = 0;
7688 if( iActive >= iItemNum ) {
7689 iActive = mSortCategory[0].empty() ? 0 : 1;
7690 }
7691 } else if( action == "RIGHT" ) {
7692 if( !filtered_items.empty() && activeItem ) {
7693 if( ++page_num >= static_cast<int>( activeItem->vIG.size() ) ) {
7694 page_num = activeItem->vIG.size() - 1;
7695 }
7696 }
7697 } else if( action == "LEFT" ) {
7698 page_num = std::max( 0, page_num - 1 );
7699 } else if( action == "PAGE_UP" ) {
7700 iScrollPos--;
7701 } else if( action == "PAGE_DOWN" ) {
7702 iScrollPos++;
7703 } else if( action == "NEXT_TAB" || action == "PREV_TAB" ) {
7704 u.view_offset = stored_view_offset;
7706 }
7707
7708 active_pos = tripoint_zero;
7709 activeItem = nullptr;
7710
7711 if( mSortCategory[iActive].empty() ) {
7712 auto iter = filtered_items.begin();
7713 for( int iNum = 0; iter != filtered_items.end() && iNum < iActive; iNum++ ) {
7714 if( mSortCategory[iNum].empty() ) {
7715 ++iter;
7716 }
7717 }
7718 if( iter != filtered_items.end() ) {
7719 active_pos = iter->vIG[page_num].pos;
7720 activeItem = &( *iter );
7721 }
7722 }
7723
7724 if( activeItem ) {
7725 centerlistview( active_pos, width );
7726 trail_start = u.pos();
7727 trail_end = u.pos() + active_pos;
7728 // Actually accessed from the terrain overlay callback `trail_cb` in the
7729 // call to `ui_manager::redraw`.
7730 //NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores)
7731 trail_end_x = true;
7732 } else {
7733 u.view_offset = stored_view_offset;
7734 trail_start = trail_end = std::nullopt;
7735 }
7737
7739
7740 action = ctxt.handle_input();
7741 } while( action != "QUIT" );
7742
7743 u.view_offset = stored_view_offset;
7744 return game::vmenu_ret::QUIT;
7745}
constexpr T clamp(const T &val, const T &min, const T &max)
Clamp first argument so that it is no lower than second and no higher than third.
Definition: cata_utility.h:149
std::string list_item_upvote
Definition: game.h:1030
std::string list_item_downvote
Definition: game.h:1031
std::string sFilter
Definition: game.h:1029
void reset_item_list_state(const catacurses::window &window, int height, bool bRadiusSort)
Definition: game.cpp:7183
std::vector< iteminfo > info() const
Return all the information about the item and its type as a vector.
Definition: item.cpp:3993
nc_color color_in_inventory() const
Returns the color of the item depending on usefulness for the player character, e....
Definition: item.cpp:4149
std::string type_name(unsigned int quantity=1) const
Name of the item type (not the item), with proper plural.
Definition: item.cpp:9858
static bool map_item_stack_sort(const map_item_stack &lhs, const map_item_stack &rhs)
std::vector< item_group > vIG
const item * example
tripoint example_item_pos
string_input_popup & identifier(const std::string &value)
An identifier to be used to store / get the input history.
string_input_popup & text(const std::string &value)
Set / get the text that can be modified by the user.
void edit(std::string &value)
Edit values in place.
string_input_popup & width(int value)
Width (in console cells) of the input field itself.
string_input_popup & description(const std::string &value)
Additional help text, shown below the input box.
string_input_popup & title(const std::string &value)
The title: short string before the actual input field.
std::string list_item_priority
Definition: uistate.h:121
int list_item_sort
Definition: uistate.h:118
bool list_item_downvote_active
Definition: uistate.h:124
bool list_item_init
Definition: uistate.h:126
bool list_item_filter_active
Definition: uistate.h:123
std::string list_item_filter
Definition: uistate.h:119
bool list_item_priority_active
Definition: uistate.h:125
std::string list_item_downvote
Definition: uistate.h:120
direction direction_from(const coords::coord_point< Point, Origin, Scale > &loc1, const coords::coord_point< Point, Origin, Scale > &loc2)
Definition: coordinates.h:540
temperature_flag
Definition: enums.h:42
static shared_ptr_fast< game::draw_callback_t > create_trail_callback(const std::optional< tripoint > &trail_start, const std::optional< tripoint > &trail_end, const bool &trail_end_x)
Definition: game.cpp:3087
uistatedata uistate
Definition: game.cpp:288
static void centerlistview(const tripoint &active_item_position, int ui_width)
Definition: game.cpp:7028
std::string direction_name_short(const direction dir)
Definition: line.cpp:533
int list_filter_high_priority(std::vector< map_item_stack > &stack, const std::string &priorities)
std::vector< map_item_stack > filter_item_stacks(const std::vector< map_item_stack > &stack, const std::string &filter)
int list_filter_low_priority(std::vector< map_item_stack > &stack, const int start, const std::string &priorities)
void mvwprintw(const window &win, point p, const std::string &text)
void wprintw(const window &win, const std::string &text)
temperature_flag temperature_flag_for_location(const map &m, const item_location &loc)
Definition: rot.cpp:13
quantity< int, temperature_in_millidegree_celsius_tag > temperature
void calcStartPos(int &iStartPos, const int iCurrentLine, const int iContentHeight, const int iNumEntries)
Definition: output.cpp:1507
void draw_custom_border(const catacurses::window &w, const catacurses::chtype ls, const catacurses::chtype rs, const catacurses::chtype ts, const catacurses::chtype bs, const catacurses::chtype tl, const catacurses::chtype tr, const catacurses::chtype bl, const catacurses::chtype br, const nc_color FG, point pos, int height, int width)
Definition: output.cpp:524
void draw_item_filter_rules(const catacurses::window &win, int starty, int height, item_filter_type type)
Write some tips (such as precede items with - to exclude them) onto the window.
Definition: output.cpp:810
std::string remove_color_tags(const std::string &s)
Removes the color tags from the input string.
Definition: output.cpp:145
void trim_and_print(const catacurses::window &w, point begin, const int width, const nc_color &base_color, const std::string &text, const report_color_error color_error)
Prints a single line of text.
Definition: output.cpp:214
void draw_scrollbar(const catacurses::window &window, const int iCurrentLine, const int iContentHeight, const int iNumLines, point offset, nc_color bar_color, const bool bDoNotScrollToEnd)
Draw a scrollbar (Legacy function, use class scrollbar instead!)
Definition: output.cpp:1314
input_event draw_item_info(const int iLeft, const int iWidth, const int iTop, const int iHeight, item_info_data &data)
Definition: output.cpp:793
#define LINE_XOXX
Definition: output.h:47
#define LINE_XXXO
Definition: output.h:45

References _, action, add_draw_callback(), add_msg(), c_light_gray, c_light_green, c_magenta, c_red, c_white, c_yellow, calcStartPos(), centerlistview(), CHANGE_TAB, clamp(), item::color_in_inventory(), game_menus::inv::compare(), create_trail_callback(), string_input_popup::description(), direction_from(), direction_name_short(), item::display_name(), draw_custom_border(), draw_item_filter_rules(), draw_item_info(), draw_scrollbar(), string_input_popup::edit(), map_item_stack::example, map_item_stack::example_item_pos, FILTER, filter_item_stacks(), Character::get_path_avoid(), Character::get_pathfinding_settings(), input_context::handle_input(), item_info_data::handle_scrolling, high, HIGH_PRIORITY, string_input_popup::identifier(), item::info(), invalidate_main_ui_adaptor(), LINE_XOXX, LINE_XXXO, list_filter_high_priority(), list_filter_low_priority(), list_item_downvote, uistatedata::list_item_downvote, uistatedata::list_item_downvote_active, uistatedata::list_item_filter, uistatedata::list_item_filter_active, uistatedata::list_item_init, uistatedata::list_item_priority, uistatedata::list_item_priority_active, uistatedata::list_item_sort, list_item_upvote, LOW_PRIORITY, m, m_info, map_item_stack::map_item_stack_sort(), string_input_popup::max_length(), catacurses::mvwprintw(), mvwprintz(), catacurses::newwin(), point_south, point_zero, Character::pos(), string_input_popup::query_string(), QUIT, ui_manager::redraw(), input_context::register_action(), remove_color_tags(), reset_item_list_state(), rl_dist(), map::route(), Character::sees(), Character::set_destination(), sFilter, string_format(), rot::temperature_flag_for_location(), TERMX, TERMY, string_input_popup::text(), string_input_popup::title(), item::tname(), to_translation(), trim_and_print(), tripoint_zero, item::type_name(), u, uistate, utf8_width(), player::view_offset, map_item_stack::vIG, catacurses::werase(), string_input_popup::width(), item_info_data::without_border, item_info_data::without_getch, catacurses::wnoutrefresh(), catacurses::wprintw(), and wprintz().

Referenced by list_items_monsters().

◆ list_items_monsters()

void game::list_items_monsters ( )
private

Definition at line 7252 of file game.cpp.

7253{
7254 std::vector<Creature *> mons = u.get_visible_creatures( current_daylight_level( calendar::turn ) );
7255 // whole reality bubble
7256 const std::vector<map_item_stack> items = find_nearby_items( 60 );
7257
7258 if( mons.empty() && items.empty() ) {
7259 add_msg( m_info, _( "You don't see any items or monsters around you!" ) );
7260 return;
7261 }
7262
7263 std::sort( mons.begin(), mons.end(), [&]( const Creature * lhs, const Creature * rhs ) {
7264 const auto att_lhs = lhs->attitude_to( u );
7265 const auto att_rhs = rhs->attitude_to( u );
7266
7267 return att_lhs < att_rhs || ( att_lhs == att_rhs
7268 && rl_dist( u.pos(), lhs->pos() ) < rl_dist( u.pos(), rhs->pos() ) );
7269 } );
7270
7271 // If the current list is empty, switch to the non-empty list
7273 if( items.empty() ) {
7274 uistate.vmenu_show_items = false;
7275 }
7276 } else if( mons.empty() ) {
7278 }
7279
7282 while( true ) {
7283 ret = uistate.vmenu_show_items ? list_items( items ) : list_monsters( mons );
7286 } else {
7287 break;
7288 }
7289 }
7290
7291 if( ret == game::vmenu_ret::FIRE ) {
7293 }
7295}
double current_daylight_level(const time_point &p)
Returns the current seasonally-adjusted maximum daylight level.
Definition: calendar.cpp:171
game::vmenu_ret list_monsters(const std::vector< Creature * > &monster_list)
Definition: game.cpp:7747
game::vmenu_ret list_items(const std::vector< map_item_stack > &item_list)
Definition: game.cpp:7297
vmenu_ret
Definition: game.h:767
std::vector< map_item_stack > find_nearby_items(int iRadius)
Definition: game.cpp:6951
void temp_exit_fullscreen()
Definition: game.cpp:457
void reenter_fullscreen()
Definition: game.cpp:467
bool vmenu_show_items
Definition: uistate.h:122

References _, add_msg(), CHANGE_TAB, current_daylight_level(), find_nearby_items(), FIRE, avatar_action::fire_wielded_weapon(), Character::get_visible_creatures(), list_items(), list_monsters(), m_info, reenter_fullscreen(), cata::hash64_detail::ret, temp_exit_fullscreen(), calendar::turn, u, uistate, and uistatedata::vmenu_show_items.

Referenced by handle_action(), and look_around().

◆ list_missions()

void game::list_missions ( )

Definition at line 22 of file mission_ui.cpp.

23{
24 catacurses::window w_missions;
25
26 enum class tab_mode : int {
27 TAB_ACTIVE = 0,
28 TAB_COMPLETED,
29 TAB_FAILED,
30 NUM_TABS,
31 FIRST_TAB = 0,
32 LAST_TAB = NUM_TABS - 1
33 };
34 tab_mode tab = tab_mode::FIRST_TAB;
35 size_t selection = 0;
36 int entries_per_page = 0;
37 input_context ctxt( "MISSIONS" );
38 ctxt.register_cardinal();
39 ctxt.register_action( "CONFIRM" );
40 ctxt.register_action( "QUIT" );
41 ctxt.register_action( "HELP_KEYBINDINGS" );
42
44 ui.on_screen_resize( [&]( ui_adaptor & ui ) {
46
47 // content ranges from y=3 to FULL_SCREEN_HEIGHT - 2
48 entries_per_page = FULL_SCREEN_HEIGHT - 4;
49
50 ui.position_from_window( w_missions );
51 } );
52 ui.mark_resize();
53
54 std::vector<mission *> umissions;
55
56 ui.on_redraw( [&]( const ui_adaptor & ) {
57 werase( w_missions );
58 // entries_per_page * page number
59 const int top_of_page = entries_per_page * ( selection / entries_per_page );
60 const int bottom_of_page =
61 std::min( top_of_page + entries_per_page - 1, static_cast<int>( umissions.size() ) - 1 );
62
63 for( int i = 3; i < FULL_SCREEN_HEIGHT - 1; i++ ) {
64 mvwputch( w_missions, point( 30, i ), BORDER_COLOR, LINE_XOXO );
65 }
66
67 const std::vector<std::pair<tab_mode, std::string>> tabs = {
68 { tab_mode::TAB_ACTIVE, _( "ACTIVE MISSIONS" ) },
69 { tab_mode::TAB_COMPLETED, _( "COMPLETED MISSIONS" ) },
70 { tab_mode::TAB_FAILED, _( "FAILED MISSIONS" ) },
71 };
72 draw_tabs( w_missions, tabs, tab );
73 draw_border_below_tabs( w_missions );
74
75 mvwputch( w_missions, point( 30, 2 ), BORDER_COLOR,
76 tab == tab_mode::TAB_COMPLETED ? ' ' : LINE_OXXX ); // ^|^
77 mvwputch( w_missions, point( 30, FULL_SCREEN_HEIGHT - 1 ), BORDER_COLOR, LINE_XXOX ); // _|_
78
79 draw_scrollbar( w_missions, selection, entries_per_page, umissions.size(), point( 0, 3 ) );
80
81 for( int i = top_of_page; i <= bottom_of_page; i++ ) {
82 const auto miss = umissions[i];
83 const nc_color col = u.get_active_mission() == miss ? c_light_green : c_white;
84 const int y = i - top_of_page + 3;
85 trim_and_print( w_missions, point( 1, y ), 28,
86 static_cast<int>( selection ) == i ? hilite( col ) : col,
87 miss->name() );
88 }
89
90 if( selection < umissions.size() ) {
91 const auto miss = umissions[selection];
92 const nc_color col = u.get_active_mission() == miss ? c_light_green : c_white;
93 std::string for_npc;
94 if( miss->get_npc_id().is_valid() ) {
95 npc *guy = g->find_npc( miss->get_npc_id() );
96 if( guy ) {
97 for_npc = string_format( _( " for %s" ), guy->disp_name() );
98 }
99 }
100
101 int y = 3;
102 y += fold_and_print( w_missions, point( 31, y ), getmaxx( w_missions ) - 33, col,
103 miss->name() + for_npc );
104
105 auto format_tokenized_description = []( const std::string & description,
106 const std::vector<std::pair<int, itype_id>> &rewards ) {
107 std::string formatted_description = description;
108 for( const auto &reward : rewards ) {
109 std::string token = "<reward_count:" + reward.second.str() + ">";
110 formatted_description = replace_all( formatted_description, token,
111 string_format( "%d", reward.first ) );
112 }
113 return formatted_description;
114 };
115
116 y++;
117 if( !miss->get_description().empty() ) {
118 y += fold_and_print( w_missions, point( 31, y ), getmaxx( w_missions ) - 33, c_white,
119 format_tokenized_description( miss->get_description(), miss->get_likely_rewards() ) );
120 }
121 if( miss->has_deadline() ) {
122 const time_point deadline = miss->get_deadline();
123 mvwprintz( w_missions, point( 31, ++y ), c_white, _( "Deadline: %s" ), to_string( deadline ) );
124
125 if( tab != tab_mode::TAB_COMPLETED ) {
126 // There's no point in displaying this for a completed mission.
127 // @ TODO: But displaying when you completed it would be useful.
128 const time_duration remaining = deadline - calendar::turn;
129 std::string remaining_time;
130
131 if( remaining <= 0_turns ) {
132 remaining_time = _( "None!" );
133 } else if( u.has_watch() ) {
134 remaining_time = to_string( remaining );
135 } else {
136 remaining_time = to_string_approx( remaining );
137 }
138
139 mvwprintz( w_missions, point( 31, ++y ), c_white, _( "Time remaining: %s" ), remaining_time );
140 }
141 }
142 if( miss->has_target() ) {
144 // TODO: target does not contain a z-component, targets are assumed to be on z=0
145 mvwprintz( w_missions, point( 31, ++y ), c_white, _( "Target: %s You: %s" ),
146 miss->get_target().to_string(), pos.to_string() );
147 }
148 } else {
149 static const std::map< tab_mode, std::string > nope = {
150 { tab_mode::TAB_ACTIVE, translate_marker( "You have no active missions!" ) },
151 { tab_mode::TAB_COMPLETED, translate_marker( "You haven't completed any missions!" ) },
152 { tab_mode::TAB_FAILED, translate_marker( "You haven't failed any missions!" ) }
153 };
154 mvwprintz( w_missions, point( 31, 4 ), c_light_red, _( nope.at( tab ) ) );
155 }
156
157 wnoutrefresh( w_missions );
158 } );
159
160 while( true ) {
161 umissions.clear();
162 if( tab < tab_mode::FIRST_TAB || tab >= tab_mode::NUM_TABS ) {
163 debugmsg( "The sanity check failed because tab=%d", static_cast<int>( tab ) );
164 tab = tab_mode::FIRST_TAB;
165 }
166 switch( tab ) {
168 umissions = u.get_active_missions();
169 break;
170 case tab_mode::TAB_COMPLETED:
171 umissions = u.get_completed_missions();
172 break;
173 case tab_mode::TAB_FAILED:
174 umissions = u.get_failed_missions();
175 break;
176 default:
177 break;
178 }
179 if( ( !umissions.empty() && selection >= umissions.size() ) ||
180 ( umissions.empty() && selection != 0 ) ) {
181 debugmsg( "Sanity check failed: selection=%d, size=%d", static_cast<int>( selection ),
182 static_cast<int>( umissions.size() ) );
183 selection = 0;
184 }
186 const std::string action = ctxt.handle_input();
187 if( action == "RIGHT" ) {
188 tab = static_cast<tab_mode>( static_cast<int>( tab ) + 1 );
189 if( tab >= tab_mode::NUM_TABS ) {
190 tab = tab_mode::FIRST_TAB;
191 }
192 selection = 0;
193 } else if( action == "LEFT" ) {
194 tab = static_cast<tab_mode>( static_cast<int>( tab ) - 1 );
195 if( tab < tab_mode::FIRST_TAB ) {
196 tab = tab_mode::LAST_TAB;
197 }
198 selection = 0;
199 } else if( action == "DOWN" ) {
200 selection++;
201 if( selection >= umissions.size() ) {
202 selection = 0;
203 }
204 } else if( action == "UP" ) {
205 if( selection == 0 ) {
206 selection = umissions.empty() ? 0 : umissions.size() - 1;
207 } else {
208 selection--;
209 }
210 } else if( action == "CONFIRM" ) {
211 if( tab == tab_mode::TAB_ACTIVE && selection < umissions.size() ) {
212 u.set_active_mission( *umissions[selection] );
213 }
214 break;
215 } else if( action == "QUIT" ) {
216 break;
217 }
218 }
219}
std::string to_string_approx(const time_duration &dur, const bool verbose)
Returns approximate duration.
Definition: calendar.cpp:361
bool has_watch() const
Returns true if the player or their vehicle has a watch.
Definition: character.cpp:731
void set_active_mission(mission &cur_mission)
Set which mission is active.
Definition: avatar.cpp:215
mission * get_active_mission() const
Returns the mission that is currently active.
Definition: avatar.cpp:194
std::vector< mission * > get_completed_missions() const
Definition: avatar.cpp:184
std::vector< mission * > get_active_missions() const
Definition: avatar.cpp:179
std::vector< mission * > get_failed_missions() const
Definition: avatar.cpp:189
A point in the game time.
Definition: calendar.h:431
nc_color hilite(const nc_color &c)
Definition: color.cpp:509
void draw_tabs(const catacurses::window &w, const std::vector< std::string > &tab_texts, size_t current_tab)
Definition: output.cpp:1274
void draw_border_below_tabs(const catacurses::window &w, nc_color border_color)
Definition: output.cpp:587
int fold_and_print(const catacurses::window &w, point begin, int width, const nc_color &base_color, const std::string &text, const char split)
Fold and print text in the given window.
Definition: output.cpp:299
#define LINE_XXOX
Definition: output.h:46
#define BORDER_COLOR
Definition: output.h:92
std::string replace_all(std::string input, const std::string &what, const std::string &with)
Replace all occurences of 'what' within 'input' with 'with'.
#define translate_marker(x)
Marks a string literal to be extracted for translation.
Definition: translations.h:30
catacurses::window new_centered_win(int nlines, int ncols)
Definition: ui.cpp:30

References _, action, BORDER_COLOR, c_light_green, c_light_red, c_white, debugmsg, Character::disp_name(), draw_border_below_tabs(), draw_scrollbar(), draw_tabs(), fold_and_print(), FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH, g, avatar::get_active_mission(), avatar::get_active_missions(), avatar::get_completed_missions(), avatar::get_failed_missions(), catacurses::getmaxx(), Character::global_omt_location(), input_context::handle_input(), Character::has_watch(), hilite(), LINE_OXXX, LINE_XOXO, LINE_XXOX, mvwprintz(), mvwputch(), new_centered_win(), ui_manager::redraw(), input_context::register_action(), input_context::register_cardinal(), replace_all(), avatar::set_active_mission(), string_format(), anonymous_namespace{bionics_ui.cpp}::TAB_ACTIVE, coords::coord_point< Point, Origin, Scale >::to_string(), to_string(), to_string_approx(), translate_marker, trim_and_print(), calendar::turn, u, catacurses::werase(), and catacurses::wnoutrefresh().

Referenced by handle_action().

◆ list_monsters()

game::vmenu_ret game::list_monsters ( const std::vector< Creature * > &  monster_list)
private

Definition at line 7747 of file game.cpp.

7748{
7749 const int iInfoHeight = 15;
7750 const int width = 45;
7751 int offsetX = 0;
7752 int iMaxRows = 0;
7753
7754 catacurses::window w_monsters;
7755 catacurses::window w_monsters_border;
7756 catacurses::window w_monster_info;
7757 catacurses::window w_monster_info_border;
7758
7759 Creature *cCurMon = nullptr;
7760 tripoint iActivePos;
7761
7762 bool hide_ui = false;
7763
7764 ui_adaptor ui;
7765 ui.on_screen_resize( [&]( ui_adaptor & ui ) {
7766 if( hide_ui ) {
7767 ui.position( point_zero, point_zero );
7768 } else {
7769 offsetX = TERMX - width;
7770 iMaxRows = TERMY - iInfoHeight - 1;
7771
7772 w_monsters = catacurses::newwin( iMaxRows, width - 2, point( offsetX + 1,
7773 1 ) );
7774 w_monsters_border = catacurses::newwin( iMaxRows + 1, width, point( offsetX,
7775 0 ) );
7776 w_monster_info = catacurses::newwin( iInfoHeight - 2, width - 2,
7777 point( offsetX + 1, TERMY - iInfoHeight + 1 ) );
7778 w_monster_info_border = catacurses::newwin( iInfoHeight, width, point( offsetX,
7779 TERMY - iInfoHeight ) );
7780
7781 if( cCurMon ) {
7782 centerlistview( iActivePos, width );
7783 }
7784
7785 ui.position( point( offsetX, 0 ), point( width, TERMY ) );
7786 }
7787 } );
7788 ui.mark_resize();
7789
7790 const int max_gun_range = u.primary_weapon().gun_range( &u );
7791
7792 const tripoint stored_view_offset = u.view_offset;
7794
7795 int iActive = 0; // monster index that we're looking at
7796
7797 std::string action;
7798 input_context ctxt( "LIST_MONSTERS" );
7799 ctxt.register_action( "UP", to_translation( "Move cursor up" ) );
7800 ctxt.register_action( "DOWN", to_translation( "Move cursor down" ) );
7801 ctxt.register_action( "NEXT_TAB" );
7802 ctxt.register_action( "PREV_TAB" );
7803 ctxt.register_action( "SAFEMODE_BLACKLIST_ADD" );
7804 ctxt.register_action( "SAFEMODE_BLACKLIST_REMOVE" );
7805 ctxt.register_action( "QUIT" );
7806 if( bVMonsterLookFire ) {
7807 ctxt.register_action( "look" );
7808 ctxt.register_action( "fire" );
7809 }
7810 ctxt.register_action( "HELP_KEYBINDINGS" );
7811
7812 // first integer is the row the attitude category string is printed in the menu
7813 std::map<int, Creature::Attitude> mSortCategory;
7814
7815 for( int i = 0, last_attitude = -1; i < static_cast<int>( monster_list.size() ); i++ ) {
7816 const auto attitude = monster_list[i]->attitude_to( u );
7817 if( attitude != last_attitude ) {
7818 mSortCategory[i + mSortCategory.size()] = attitude;
7819 last_attitude = attitude;
7820 }
7821 }
7822
7823 ui.on_redraw( [&]( const ui_adaptor & ) {
7824 if( !hide_ui ) {
7825 draw_custom_border( w_monsters_border, true, true, true, true, true, true, LINE_XOXO, LINE_XOXO );
7826 draw_custom_border( w_monster_info_border, true, true, true, true, LINE_XXXO, LINE_XOXX, true,
7827 true );
7828
7829 mvwprintz( w_monsters_border, point( 2, 0 ), c_light_green, "<Tab> " );
7830 wprintz( w_monsters_border, c_white, _( "Monsters" ) );
7831
7832 if( monster_list.empty() ) {
7833 werase( w_monsters );
7834 mvwprintz( w_monsters, point( 2, iMaxRows / 3 ), c_white,
7835 _( "You don't see any monsters around you!" ) );
7836 } else {
7837 werase( w_monsters );
7838
7839 const int iNumMonster = monster_list.size();
7840 const int iMenuSize = monster_list.size() + mSortCategory.size();
7841
7842 const int numw = iNumMonster > 999 ? 4 :
7843 iNumMonster > 99 ? 3 :
7844 iNumMonster > 9 ? 2 : 1;
7845
7846 // given the currently selected monster iActive. get the selected row
7847 int iSelPos = iActive;
7848 for( auto &ia : mSortCategory ) {
7849 int index = ia.first;
7850 if( index <= iSelPos ) {
7851 ++iSelPos;
7852 } else {
7853 break;
7854 }
7855 }
7856 int iStartPos = 0;
7857 // use selected row get the start row
7858 calcStartPos( iStartPos, iSelPos, iMaxRows - 1, iMenuSize );
7859
7860 // get first visible monster and category
7861 int iCurMon = iStartPos;
7862 auto CatSortIter = mSortCategory.cbegin();
7863 while( CatSortIter != mSortCategory.cend() && CatSortIter->first < iStartPos ) {
7864 ++CatSortIter;
7865 --iCurMon;
7866 }
7867
7868 const auto endY = std::min<int>( iMaxRows - 1, iMenuSize );
7869 for( int y = 0; y < endY; ++y ) {
7870 if( CatSortIter != mSortCategory.cend() ) {
7871 const int iCurPos = iStartPos + y;
7872 const int iCatPos = CatSortIter->first;
7873 if( iCurPos == iCatPos ) {
7874 const std::string cat_name = Creature::get_attitude_ui_data(
7875 CatSortIter->second ).first.translated();
7876 mvwprintz( w_monsters, point( 1, y ), c_magenta, cat_name );
7877 ++CatSortIter;
7878 continue;
7879 }
7880 }
7881 // select current monster
7882 const auto critter = monster_list[iCurMon];
7883 const bool selected = iCurMon == iActive;
7884 ++iCurMon;
7885 if( critter->sees( g->u ) ) {
7886 mvwprintz( w_monsters, point( 0, y ), c_yellow, "!" );
7887 }
7888 bool is_npc = false;
7889 const monster *m = dynamic_cast<monster *>( critter );
7890 const npc *p = dynamic_cast<npc *>( critter );
7891 nc_color name_color = critter->basic_symbol_color();
7892
7893 if( selected ) {
7894 name_color = hilite( name_color );
7895 }
7896
7897 if( m != nullptr ) {
7898 trim_and_print( w_monsters, point( 1, y ), width - 26, name_color, m->name() );
7899 } else {
7900 trim_and_print( w_monsters, point( 1, y ), width - 26, name_color, critter->disp_name() );
7901 is_npc = true;
7902 }
7903
7904 if( selected && !get_safemode().empty() ) {
7905 const std::string monName = is_npc ? get_safemode().npc_type_name() : m->name();
7906
7907 std::string sSafemode;
7908 if( get_safemode().has_rule( monName, Creature::A_ANY ) ) {
7909 sSafemode = _( "<R>emove from safemode Blacklist" );
7910 } else {
7911 sSafemode = _( "<A>dd to safemode Blacklist" );
7912 }
7913
7914 shortcut_print( w_monsters, point( 2, getmaxy( w_monsters ) - 1 ),
7915 c_white, c_light_green, sSafemode );
7916 }
7917
7919 std::string sText;
7920
7921 if( m != nullptr ) {
7922 m->get_HP_Bar( color, sText );
7923 } else {
7924 std::tie( sText, color ) =
7925 ::get_hp_bar( critter->get_hp(), critter->get_hp_max(), false );
7926 }
7927 mvwprintz( w_monsters, point( width - 25, y ), color, sText );
7928
7929 if( m != nullptr ) {
7930 const auto att = m->get_attitude();
7931 sText = att.first;
7932 color = att.second;
7933 } else if( p != nullptr ) {
7934 sText = npc_attitude_name( p->get_attitude() );
7935 color = p->symbol_color();
7936 }
7937 mvwprintz( w_monsters, point( width - 19, y ), color, sText );
7938
7939 const int mon_dist = rl_dist( u.pos(), critter->pos() );
7940 const int numd = mon_dist > 999 ? 4 :
7941 mon_dist > 99 ? 3 :
7942 mon_dist > 9 ? 2 : 1;
7943
7944 trim_and_print( w_monsters, point( width - ( 8 + numd ), y ), 6 + numd,
7945 selected ? c_light_green : c_light_gray,
7946 "%*d %s",
7947 numd, mon_dist,
7948 direction_name_short( direction_from( u.pos(), critter->pos() ) ) );
7949 }
7950
7951 mvwprintz( w_monsters_border, point( ( width / 2 ) - numw - 2, 0 ), c_light_green, " %*d", numw,
7952 iActive + 1 );
7953 wprintz( w_monsters_border, c_white, " / %*d ", numw, static_cast<int>( monster_list.size() ) );
7954
7955 werase( w_monster_info );
7956 if( cCurMon ) {
7957 cCurMon->print_info( w_monster_info, 1, iInfoHeight - 3, 1 );
7958 }
7959
7960 draw_custom_border( w_monster_info_border, true, true, true, true, LINE_XXXO, LINE_XOXX, true,
7961 true );
7962
7963 if( bVMonsterLookFire ) {
7964 mvwprintw( w_monster_info_border, point_east, "< " );
7965 wprintz( w_monster_info_border, c_light_green, ctxt.press_x( "look" ) );
7966 wprintz( w_monster_info_border, c_light_gray, " %s", _( "to look around" ) );
7967
7968 if( cCurMon && rl_dist( u.pos(), cCurMon->pos() ) <= max_gun_range ) {
7969 wprintw( w_monster_info_border, " " );
7970 wprintz( w_monster_info_border, c_light_green, ctxt.press_x( "fire" ) );
7971 wprintz( w_monster_info_border, c_light_gray, " %s", _( "to shoot" ) );
7972 }
7973 wprintw( w_monster_info_border, " >" );
7974 }
7975
7976 draw_scrollbar( w_monsters_border, iActive, iMaxRows, static_cast<int>( monster_list.size() ),
7977 point_south );
7978 }
7979
7980 wnoutrefresh( w_monsters_border );
7981 wnoutrefresh( w_monster_info_border );
7982 wnoutrefresh( w_monsters );
7983 wnoutrefresh( w_monster_info );
7984 }
7985 } );
7986
7987 std::optional<tripoint> trail_start;
7988 std::optional<tripoint> trail_end;
7989 bool trail_end_x = false;
7990 shared_ptr_fast<draw_callback_t> trail_cb = create_trail_callback( trail_start, trail_end,
7991 trail_end_x );
7992 add_draw_callback( trail_cb );
7993
7994 do {
7995 if( action == "UP" ) {
7996 iActive--;
7997 if( iActive < 0 ) {
7998 if( monster_list.empty() ) {
7999 iActive = 0;
8000 } else {
8001 iActive = static_cast<int>( monster_list.size() ) - 1;
8002 }
8003 }
8004 } else if( action == "DOWN" ) {
8005 iActive++;
8006 if( iActive >= static_cast<int>( monster_list.size() ) ) {
8007 iActive = 0;
8008 }
8009 } else if( action == "NEXT_TAB" || action == "PREV_TAB" ) {
8010 u.view_offset = stored_view_offset;
8012 } else if( action == "SAFEMODE_BLACKLIST_REMOVE" ) {
8013 const auto m = dynamic_cast<monster *>( cCurMon );
8014 const std::string monName = ( m != nullptr ) ? m->name() : "human";
8015
8016 if( get_safemode().has_rule( monName, Creature::A_ANY ) ) {
8018 }
8019 } else if( action == "SAFEMODE_BLACKLIST_ADD" ) {
8020 if( !get_safemode().empty() ) {
8021 const auto m = dynamic_cast<monster *>( cCurMon );
8022 const std::string monName = ( m != nullptr ) ? m->name() : "human";
8023
8024 get_safemode().add_rule( monName, Creature::A_ANY, get_option<int>( "SAFEMODEPROXIMITY" ),
8026 }
8027 } else if( action == "look" ) {
8028 hide_ui = true;
8029 ui.mark_resize();
8030 look_around();
8031 hide_ui = false;
8032 ui.mark_resize();
8033 } else if( action == "fire" ) {
8034 if( cCurMon != nullptr && rl_dist( u.pos(), cCurMon->pos() ) <= max_gun_range ) {
8035 u.last_target = shared_from( *cCurMon );
8036 add_msg( "Target_set" );
8038 u.view_offset = stored_view_offset;
8039 return game::vmenu_ret::FIRE;
8040 }
8041 }
8042
8043 if( iActive >= 0 && static_cast<size_t>( iActive ) < monster_list.size() ) {
8044 cCurMon = monster_list[iActive];
8045 iActivePos = cCurMon->pos() - u.pos();
8046 centerlistview( iActivePos, width );
8047 trail_start = u.pos();
8048 trail_end = cCurMon->pos();
8049 // Actually accessed from the terrain overlay callback `trail_cb` in the
8050 // call to `ui_manager::redraw`.
8051 //NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores)
8052 trail_end_x = false;
8053 } else {
8054 cCurMon = nullptr;
8055 iActivePos = tripoint_zero;
8056 u.view_offset = stored_view_offset;
8057 trail_start = trail_end = std::nullopt;
8058 }
8060
8062
8063 action = ctxt.handle_input();
8064 } while( action != "QUIT" );
8065
8066 u.view_offset = stored_view_offset;
8067
8068 return game::vmenu_ret::QUIT;
8069}
double recoil
Definition: character.h:571
nc_color symbol_color() const override
Definition: character.cpp:6048
static const std::pair< translation, nc_color > & get_attitude_ui_data(Attitude att)
Creature Attitude as String and color.
Definition: creature.cpp:1920
virtual const tripoint & pos() const =0
virtual int print_info(const catacurses::window &w, int vStart, int vLines, int column) const =0
Write information about this creature.
shared_ptr_fast< T > shared_from(const T &critter)
Returns a shared pointer to the given critter (which can be of any of the subclasses of Creature).
Definition: game.cpp:4592
bool bVMonsterLookFire
Definition: game.h:1034
int gun_range(const player *p) const
The weapons range in map squares.
Definition: item.cpp:7359
npc_attitude get_attitude() const
Definition: npc.cpp:3163
weak_ptr_fast< Creature > last_target
Definition: player.h:241
bool has_rule(const std::string &rule_in, Creature::Attitude attitude_in)
void remove_rule(const std::string &rule_in, Creature::Attitude attitude_in)
static nc_color color(const T_t &t)
@ RULE_BLACKLISTED
Definition: enums.h:54
constexpr double MAX_RECOIL
std::string npc_attitude_name(npc_attitude att)
Definition: npc.cpp:2567
std::pair< std::string, nc_color > get_hp_bar(const int cur_hp, const int max_hp, const bool is_mon)
Definition: output.cpp:1604
size_t shortcut_print(const catacurses::window &w, point p, nc_color text_color, nc_color shortcut_color, const std::string &fmt)
Definition: output.cpp:1543

References _, Creature::A_ANY, action, add_draw_callback(), add_msg(), safemode::add_rule(), bVMonsterLookFire, c_light_gray, c_light_green, c_magenta, c_white, c_yellow, calcStartPos(), centerlistview(), CHANGE_TAB, color(), create_trail_callback(), direction_from(), direction_name_short(), draw_custom_border(), draw_scrollbar(), FIRE, g, npc::get_attitude(), Creature::get_attitude_ui_data(), get_hp_bar(), get_safemode(), catacurses::getmaxy(), item::gun_range(), input_context::handle_input(), safemode::has_rule(), hilite(), invalidate_main_ui_adaptor(), player::last_target, LINE_XOXO, LINE_XOXX, LINE_XXXO, look_around(), m, MAX_RECOIL, catacurses::mvwprintw(), mvwprintz(), map::name(), catacurses::newwin(), npc_attitude_name(), safemode::npc_type_name(), point_east, point_south, point_zero, Creature::pos(), Character::pos(), input_context::press_x(), Character::primary_weapon(), Creature::print_info(), QUIT, Character::recoil, ui_manager::redraw(), input_context::register_action(), safemode::remove_rule(), rl_dist(), RULE_BLACKLISTED, shared_from(), shortcut_print(), Character::symbol_color(), TERMX, TERMY, to_translation(), trim_and_print(), tripoint_zero, u, player::view_offset, catacurses::werase(), catacurses::wnoutrefresh(), catacurses::wprintw(), and wprintz().

Referenced by list_items_monsters().

◆ load() [1/2]

bool game::load ( const save_t name)
private

Definition at line 2540 of file game.cpp.

2541{
2544 popup.message( "%s", _( "Please wait…\nLoading the save…" ) );
2547
2548 using namespace std::placeholders;
2549
2550 const std::string worldpath = get_world_base_save_path() + "/";
2551 const std::string playerpath = worldpath + name.base_path();
2552
2553 // Now load up the master game data; factions (and more?)
2554 load_master();
2555 u = avatar();
2556 u.set_save_id( name.decoded_name() );
2557 u.name = name.decoded_name();
2558 if( !read_from_file( playerpath + SAVE_EXTENSION, std::bind( &game::unserialize, this, _1 ) ) ) {
2559 return false;
2560 }
2561
2563 u.get_avatar_diary()->load();
2564
2566
2567 read_from_file_optional( worldpath + name.base_path() + SAVE_EXTENSION_LOG,
2568 std::bind( &memorial_logger::load, &memorial(), _1 ) );
2569
2570#if defined(__ANDROID__)
2571 read_from_file_optional( worldpath + name.base_path() + SAVE_EXTENSION_SHORTCUTS,
2572 std::bind( &game::load_shortcuts, this, _1 ) );
2573#endif
2574
2575 // Now that the player's worn items are updated, their sight limits need to be
2576 // recalculated. (This would be cleaner if u.worn were private.)
2578
2579 if( !gamemode ) {
2580 gamemode = std::make_unique<special_game>();
2581 }
2582
2583 safe_mode = get_option<bool>( "SAFEMODE" ) ? SAFE_MODE_ON : SAFE_MODE_OFF;
2584 mostseen = 0; // ...and mostseen is 0, we haven't seen any monsters yet.
2585
2586 init_autosave();
2587 get_auto_pickup().load_character(); // Load character auto pickup rules
2588 get_auto_notes_settings().load(); // Load character auto notes settings
2589 get_safemode().load_character(); // Load character safemode rules
2590 zone_manager::get_manager().load_zones(); // Load character world zones
2591 read_from_file_optional( get_world_base_save_path() + "/uistate.json", []( std::istream & stream ) {
2592 JsonIn jsin( stream );
2593 uistate.deserialize( jsin );
2594 } );
2595 reload_npcs();
2600 update_map( u );
2601 for( auto &e : u.inv_dump() ) {
2602 e->set_owner( g->u );
2603 }
2604 // legacy, needs to be here as we access the map.
2605 if( !u.getID().is_valid() ) {
2606 // player does not have a real id, so assign a new one,
2607 u.setID( assign_npc_id() );
2608 // The vehicle stores the IDs of the boarded players, so update it, too.
2609 if( u.in_vehicle ) {
2610 if( const std::optional<vpart_reference> vp = m.veh_at(
2611 u.pos() ).part_with_feature( "BOARDABLE", true ) ) {
2612 vp->part().passenger_id = u.getID();
2613 }
2614 }
2615 }
2616
2617 // populate calendar caches now, after active world is set, but before we do
2618 // anything else, to ensure they pick up the correct value from the save's
2619 // worldoptions
2620 calendar::set_eternal_season( ::get_option<bool>( "ETERNAL_SEASON" ) );
2621 calendar::set_season_length( ::get_option<int>( "SEASON_LENGTH" ) );
2622
2623 u.reset();
2624
2626
2628
2629 return true;
2630}
bool read_from_file(const std::string &path, const std::function< void(std::istream &)> &reader)
Try to open and read from given file using the given callback.
bool read_from_file_optional(const std::string &path, const std::function< void(std::istream &)> &reader)
void setID(character_id i, bool force=false)
Definition: character.cpp:483
std::vector< item * > inv_dump()
Definition: character.cpp:8966
void recalc_sight_limits()
Modifies the player's sight values Must be called when any of the following change: This must be call...
Definition: character.cpp:1630
void reset() override
Handles stat and bonus reset.
Definition: character.cpp:3646
Definition: json.h:172
Definition: avatar.h:55
void set_save_id(const std::string &id)
Definition: avatar.h:91
void load_map_memory()
Definition: avatar.cpp:138
Helper class that fills the background and obscures all UIs below.
Definition: ui_manager.h:193
bool is_valid() const
Definition: character_id.h:19
void load()
Definition: diary.cpp:810
void validate_linked_vehicles()
validate towed vehicles so they get linked up again after a load
Definition: game.cpp:1894
void reload_npcs()
Unloads, then loads the NPCs.
Definition: game.cpp:879
void validate_camps()
validate camps to ensure they are on the overmap list
Definition: game.cpp:1952
void load_master()
Definition: game.cpp:2509
void validate_mounted_npcs()
Definition: game.cpp:1909
character_id assign_npc_id()
Definition: game.cpp:3581
void unserialize(std::istream &fin)
Definition: savegame.cpp:167
void init_autosave()
Definition: game.cpp:11316
void validate_npc_followers()
validate list of followers to account for overmap buffers
Definition: game.cpp:1928
void load(std::istream &fin)
Loads the data in a memorial file from the given ifstream.
void load_character()
Create a popup on the UI stack that gets displayed but receives no input itself.
Definition: popup.h:278
void deserialize(const JsonObject &jo)
time_point nextweather
Definition: weather.h:205
void load_zones()
Definition: clzones.cpp:1217
static const std::string SAVE_EXTENSION(".sav")
static const std::string SAVE_EXTENSION_SHORTCUTS(".shortcuts")
static const std::string SAVE_EXTENSION_LOG(".log")
void set_season_length(int dur)
Definition: calendar.cpp:478
void set_eternal_season(bool is_eternal_season)
Definition: calendar.cpp:470
void run_on_game_load_hooks(lua_state &state)
Definition: catalua.cpp:423
bool load_world_lua_state(const std::string &)
Definition: catalua.cpp:69

References _, assign_npc_id(), uistatedata::deserialize(), g, gamemode, get_auto_notes_settings(), get_auto_pickup(), avatar::get_avatar_diary(), DynamicDataLoader::get_instance(), zone_manager::get_manager(), get_safemode(), get_weather, get_world_base_save_path(), Character::getID(), Character::in_vehicle, init_autosave(), Character::inv_dump(), character_id::is_valid(), auto_notes::auto_note_settings::load(), diary::load(), memorial_logger::load(), auto_pickup::player_settings::load_character(), safemode::load_character(), avatar::load_map_memory(), load_master(), cata::load_world_lua_state(), zone_manager::load_zones(), m, memorial(), mostseen, Character::name, om_direction::name(), weather_manager::nextweather, optional_vpart_position::part_with_feature(), popup(), Character::pos(), read_from_file(), read_from_file_optional(), Character::recalc_sight_limits(), ui_manager::redraw(), refresh_display(), reload_npcs(), Character::reset(), cata::run_on_game_load_hooks(), safe_mode, SAFE_MODE_OFF, SAFE_MODE_ON, SAVE_EXTENSION(), SAVE_EXTENSION_LOG(), SAVE_EXTENSION_SHORTCUTS(), calendar::set_eternal_season(), avatar::set_save_id(), calendar::set_season_length(), Character::setID(), calendar::turn, u, uistate, unserialize(), update_map(), validate_camps(), validate_linked_vehicles(), validate_mounted_npcs(), validate_npc_followers(), and map::veh_at().

◆ load() [2/2]

bool game::load ( const std::string &  world)

Attempt to load first valid save (if any) in world.

Definition at line 2516 of file game.cpp.

2517{
2518 world_generator->init();
2519 const WORLDPTR wptr = world_generator->get_world( world );
2520 if( !wptr ) {
2521 return false;
2522 }
2523 if( wptr->world_saves.empty() ) {
2524 debugmsg( "world '%s' contains no saves", world );
2525 return false;
2526 }
2527
2528 try {
2529 world_generator->set_active_world( wptr );
2530 g->setup();
2531 g->load( wptr->world_saves.front() );
2532 } catch( const std::exception &err ) {
2533 debugmsg( "cannot load world '%s': %s", world, err.what() );
2534 return false;
2535 }
2536
2537 return true;
2538}
std::vector< save_t > world_saves
Definition: worldfactory.h:62

References debugmsg, g, world_generator, and WORLD::world_saves.

Referenced by quickload().

◆ load_map() [1/2]

void game::load_map ( const tripoint pos_sm,
bool  pump_events = false 
)

Load the main map at given location, see map::load, in global, absolute submap coordinates.

Parameters
pump_eventsIf true, handle window events during loading. If you set this to true, do ensure that the map is not accessed before this function returns (for example, UIs that draw the map should be disabled).

Definition at line 544 of file game.cpp.

545{
546 // TODO: fix point types
547 load_map( tripoint_abs_sm( pos_sm ), pump_events );
548}
void load_map(const tripoint &pos_sm, bool pump_events=false)
Load the main map at given location, see map::load, in global, absolute submap coordinates.
Definition: game.cpp:544
coords::coord_point< tripoint, coords::origin::abs, coords::sm > tripoint_abs_sm
Definition: coordinates.h:490

References load_map().

Referenced by load_map(), place_player_overmap(), start_game(), and unserialize().

◆ load_map() [2/2]

void game::load_map ( const tripoint_abs_sm pos_sm,
bool  pump_events = false 
)

Definition at line 550 of file game.cpp.

552{
553 m.load( pos_sm, true, pump_events );
554 grid_tracker_ptr->load( m );
555}
void load(const tripoint &w, bool update_vehicles, bool pump_events=false)
Load submaps into grid.
Definition: map.cpp:6750

References grid_tracker_ptr, map::load(), and m.

◆ load_master()

void game::load_master ( )
private

Definition at line 2509 of file game.cpp.

2510{
2511 using namespace std::placeholders;
2512 const auto datafile = get_world_base_save_path() + "/" + SAVE_MASTER;
2513 read_from_file_optional( datafile, std::bind( &game::unserialize_master, this, _1 ) );
2514}
void unserialize_master(std::istream &fin)
Definition: savegame.cpp:1193
static const std::string SAVE_MASTER("master.gsav")

References get_world_base_save_path(), read_from_file_optional(), SAVE_MASTER(), and unserialize_master().

Referenced by load(), and start_game().

◆ load_npcs()

void game::load_npcs ( )

Makes any nearby NPCs on the overmap active.

Definition at line 817 of file game.cpp.

818{
819 const int radius = HALF_MAPSIZE - 1;
820 // uses submap coordinates
821 std::vector<shared_ptr_fast<npc>> just_added;
822 for( const auto &temp : overmap_buffer.get_npcs_near_player( radius ) ) {
823 const character_id &id = temp->getID();
824 const auto found = std::find_if( active_npc.begin(), active_npc.end(),
825 [id]( const shared_ptr_fast<npc> &n ) {
826 return n->getID() == id;
827 } );
828 if( found != active_npc.end() ) {
829 continue;
830 }
831 if( temp->is_active() ) {
832 continue;
833 }
834 if( temp->has_companion_mission() ) {
835 continue;
836 }
837
838 const tripoint sm_loc = temp->global_sm_location();
839 // NPCs who are out of bounds before placement would be pushed into bounds
840 // This can cause NPCs to teleport around, so we don't want that
841 if( sm_loc.x < get_levx() || sm_loc.x >= get_levx() + MAPSIZE ||
842 sm_loc.y < get_levy() || sm_loc.y >= get_levy() + MAPSIZE ||
843 ( sm_loc.z != get_levz() && !m.has_zlevels() ) ) {
844 continue;
845 }
846
847 add_msg( m_debug, "game::load_npcs: Spawning static NPC, %d:%d:%d (%d:%d:%d)",
848 get_levx(), get_levy(), get_levz(), sm_loc.x, sm_loc.y, sm_loc.z );
849 temp->place_on_map();
850 if( !m.inbounds( temp->pos() ) ) {
851 continue;
852 }
853 // In the rare case the npc was marked for death while
854 // it was on the overmap. Kill it.
855 if( temp->marked_for_death ) {
856 temp->die( nullptr );
857 } else {
858 active_npc.push_back( temp );
859 just_added.push_back( temp );
860 }
861 }
862
863 for( const auto &npc : just_added ) {
864 npc->on_load();
865 }
866
867 npcs_dirty = false;
868}
void on_load()
Retroactively update npc.
Definition: npc.cpp:2680
static constexpr int MAPSIZE

References active_npc, add_msg(), get_levx(), get_levy(), get_levz(), overmapbuffer::get_npcs_near_player(), HALF_MAPSIZE, map::has_zlevels(), map::inbounds(), m, m_debug, MAPSIZE, npcs_dirty, npc::on_load(), overmap_buffer, tripoint::x, tripoint::y, and tripoint::z.

Referenced by do_turn(), perhaps_add_random_npc(), place_player_overmap(), reload_npcs(), save_cyborg(), spawn_hallucination(), start_game(), and update_map().

◆ load_static_data()

void game::load_static_data ( )

Loads static data that does not depend on mods or similar.

Definition at line 340 of file game.cpp.

341{
342 // UI stuff, not mod-specific per definition
343 inp_mngr.init(); // Load input config JSON
344 // Init mappings for loading the json stuff
346 fullscreen = false;
347 was_fullscreen = false;
348 show_panel_adm = false;
350
351 // These functions do not load stuff from json.
352 // The content they load/initialize is hardcoded into the program.
353 // Therefore they can be loaded here.
354 // If this changes (if they load data from json), they have to
355 // be moved to game::load_mod
356
360}
bool was_fullscreen
Definition: game.h:1016
bool fullscreen
Definition: game.h:1015
void init()
Initializes the input manager, aka loads the input mapping configuration JSON.
Definition: input.cpp:111
void init()
Definition: panels.cpp:2202
void load_global()

References fullscreen, get_auto_pickup(), get_distraction_manager(), DynamicDataLoader::get_instance(), panel_manager::get_manager(), get_safemode(), input_manager::init(), panel_manager::init(), inp_mngr, distraction_manager::distraction_manager_gui::load(), auto_pickup::player_settings::load_global(), safemode::load_global(), show_panel_adm, and was_fullscreen.

◆ look_around() [1/2]

std::optional< tripoint > game::look_around ( bool  force_3d = false)

Definition at line 6599 of file game.cpp.

6600{
6602 look_around_result result = look_around( /*show_window=*/true, center, center, false, false,
6603 false, false, tripoint_zero, force_3d );
6604 return result.position;
6605}

References center, look_around(), Character::pos(), tripoint_zero, u, and player::view_offset.

Referenced by chat(), handle_action(), list_monsters(), look_around(), peek(), and zones_manager().

◆ look_around() [2/2]

look_around_result game::look_around ( bool  show_window,
tripoint center,
const tripoint start_point,
bool  has_first_point,
bool  select_zone,
bool  peeking,
bool  is_moving_zone = false,
const tripoint end_point = tripoint_zero,
bool  force_3d = false 
)
Parameters
show_windowdisplay the info window that holds the tile information in the position.
centerused to calculate the u.view_offset, could center the screen to the position it represents
start_pointthe start point of the targeting zone, also the initial local position of the cursor
has_first_pointshould be true if the first point has been selected when editing the zone
select_zonetrue if the zone is being edited
peekingdetermines if the player is peeking
is_moving_zonetrue if the zone is being moved, false by default
end_pointthe end point of the targeting zone, only used if is_moving_zone is true, default is tripoint_zero
Returns
look_around_result

Definition at line 6607 of file game.cpp.

6610{
6611 bVMonsterLookFire = false;
6612 // TODO: Make this `true`
6613 const bool allow_zlev_move = m.has_zlevels() && ( get_option<bool>( "FOV_3D" ) || force_3d );
6614
6616
6617 tripoint lp = is_moving_zone ? ( start_point + end_point ) / 2 : start_point; // cursor
6618 int &lx = lp.x;
6619 int &ly = lp.y;
6620 int &lz = lp.z;
6621
6622 int soffset = get_option<int>( "FAST_SCROLL_OFFSET" );
6623 bool fast_scroll = false;
6624
6625 std::unique_ptr<ui_adaptor> ui;
6626 catacurses::window w_info;
6627 if( show_window ) {
6628 ui = std::make_unique<ui_adaptor>();
6629 ui->on_screen_resize( [&]( ui_adaptor & ui ) {
6630 int panel_width = panel_manager::get_manager().get_current_layout().begin()->get_width();
6632
6633 // If particularly small, base height on panel width irrespective of other elements.
6634 // Value here is attempting to get a square-ish result assuming 1x2 proportioned font.
6635 if( height < panel_width / 2 ) {
6636 height = panel_width / 2;
6637 }
6638
6639 int la_y = 0;
6640 int la_x = TERMX - panel_width;
6641 std::string position = get_option<std::string>( "LOOKAROUND_POSITION" );
6642 if( position == "left" ) {
6643 if( get_option<std::string>( "SIDEBAR_POSITION" ) == "right" ) {
6645 } else {
6646 la_x = panel_manager::get_manager().get_width_left() - panel_width;
6647 }
6648 }
6649 int la_h = height;
6650 int la_w = panel_width;
6651 w_info = catacurses::newwin( la_h, la_w, point( la_x, la_y ) );
6652
6653 ui.position_from_window( w_info );
6654 } );
6655 ui->mark_resize();
6656 }
6657
6658 std::string action;
6659 input_context ctxt( "LOOK" );
6660 ctxt.set_iso( true );
6661 ctxt.register_directions();
6662 ctxt.register_action( "COORDINATE" );
6663 ctxt.register_action( "LEVEL_UP" );
6664 ctxt.register_action( "LEVEL_DOWN" );
6665 ctxt.register_action( "TOGGLE_FAST_SCROLL" );
6666 ctxt.register_action( "EXTENDED_DESCRIPTION" );
6667 ctxt.register_action( "SELECT" );
6668 if( peeking ) {
6669 ctxt.register_action( "throw_blind" );
6670 }
6671 if( !select_zone ) {
6672 ctxt.register_action( "TRAVEL_TO" );
6673 ctxt.register_action( "LIST_ITEMS" );
6674 }
6675 ctxt.register_action( "MOUSE_MOVE" );
6676 ctxt.register_action( "CENTER" );
6677
6678 ctxt.register_action( "debug_scent" );
6679 ctxt.register_action( "debug_scent_type" );
6680 ctxt.register_action( "debug_temp" );
6681 ctxt.register_action( "debug_visibility" );
6682 ctxt.register_action( "debug_lighting" );
6683 ctxt.register_action( "debug_radiation" );
6684 ctxt.register_action( "debug_submap_grid" );
6685 ctxt.register_action( "debug_hour_timer" );
6686 ctxt.register_action( "CONFIRM" );
6687 ctxt.register_action( "QUIT" );
6688 ctxt.register_action( "HELP_KEYBINDINGS" );
6689 if( use_tiles ) {
6690 ctxt.register_action( "zoom_out" );
6691 ctxt.register_action( "zoom_in" );
6692 }
6693#if defined(TILES)
6694 ctxt.register_action( "toggle_pixel_minimap" );
6695#endif // TILES
6696
6697 const int old_levz = get_levz();
6698 const int min_levz = force_3d ? -OVERMAP_DEPTH : std::max( old_levz - fov_3d_z_range,
6699 -OVERMAP_DEPTH );
6700 const int max_levz = force_3d ? OVERMAP_HEIGHT : std::min( old_levz + fov_3d_z_range,
6702
6703 m.update_visibility_cache( old_levz );
6705
6706 bool blink = true;
6708
6709 shared_ptr_fast<draw_callback_t> ter_indicator_cb;
6710
6711 if( show_window && ui ) {
6712 ui->on_redraw( [&]( const ui_adaptor & ) {
6713 werase( w_info );
6714 draw_border( w_info );
6715
6716 center_print( w_info, 0, c_white, string_format( _( "< <color_green>Look Around</color> >" ) ) );
6717
6718 std::string extended_descr_text = string_format( _( "%s - %s" ),
6719 ctxt.get_desc( "EXTENDED_DESCRIPTION" ),
6720 ctxt.get_action_name( "EXTENDED_DESCRIPTION" ) );
6721 std::string fast_scroll_text = string_format( _( "%s - %s" ),
6722 ctxt.get_desc( "TOGGLE_FAST_SCROLL" ),
6723 ctxt.get_action_name( "TOGGLE_FAST_SCROLL" ) );
6724#if defined(TILES)
6725 std::string pixel_minimap_text = string_format( _( "%s - %s" ),
6726 ctxt.get_desc( "toggle_pixel_minimap" ),
6727 ctxt.get_action_name( "toggle_pixel_minimap" ) );
6728#endif // TILES
6729
6730 center_print( w_info, getmaxy( w_info ) - 2, c_light_gray, extended_descr_text );
6731 mvwprintz( w_info, point( 1, getmaxy( w_info ) - 1 ), fast_scroll ? c_light_green : c_green,
6732 fast_scroll_text );
6733#if defined(TILES)
6734 right_print( w_info, getmaxy( w_info ) - 1, 1, pixel_minimap_option ? c_light_green : c_green,
6735 pixel_minimap_text );
6736#endif // TILES
6737
6738 int first_line = 1;
6739 const int last_line = getmaxy( w_info ) - 3;
6740 pre_print_all_tile_info( lp, w_info, first_line, last_line, cache );
6741
6742 wnoutrefresh( w_info );
6743 } );
6744 ter_indicator_cb = make_shared_fast<draw_callback_t>( [&]() {
6745 draw_look_around_cursor( lp, cache );
6746 } );
6747 add_draw_callback( ter_indicator_cb );
6748 }
6749
6750 std::optional<tripoint> zone_start;
6751 std::optional<tripoint> zone_end;
6752 bool zone_blink = false;
6753 bool zone_cursor = true;
6754 shared_ptr_fast<draw_callback_t> zone_cb = create_zone_callback( zone_start, zone_end, zone_blink,
6755 zone_cursor, is_moving_zone );
6756 add_draw_callback( zone_cb );
6757
6758 is_looking = true;
6759 const tripoint prev_offset = u.view_offset;
6760#if defined(TILES)
6761 const int prev_tileset_zoom = tileset_zoom;
6762 while( is_moving_zone && square_dist( start_point, end_point ) > 256 / get_zoom() &&
6763 get_zoom() != 4 ) {
6764 zoom_out();
6765 }
6767#endif
6768 do {
6769 u.view_offset = center - u.pos();
6770 if( select_zone ) {
6771 if( has_first_point ) {
6772 zone_start = start_point;
6773 zone_end = lp;
6774 } else {
6775 zone_start = lp;
6776 zone_end = std::nullopt;
6777 }
6778 // Actually accessed from the terrain overlay callback `zone_cb` in the
6779 // call to `ui_manager::redraw`.
6780 //NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores)
6781 zone_blink = blink;
6782 }
6783
6784 if( is_moving_zone ) {
6785 zone_start = lp - ( start_point + end_point ) / 2 + start_point;
6786 zone_end = lp - ( start_point + end_point ) / 2 + end_point;
6787 // Actually accessed from the terrain overlay callback `zone_cb` in the
6788 // call to `ui_manager::redraw`.
6789 //NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores)
6790 zone_blink = blink;
6791 }
6794 if( ( select_zone && has_first_point ) || is_moving_zone ) {
6795 ctxt.set_timeout( get_option<int>( "BLINK_SPEED" ) );
6796 }
6797
6798 //Wait for input
6799 // only specify a timeout here if "EDGE_SCROLL" is enabled
6800 // otherwise use the previously set timeout
6801 const tripoint edge_scroll = mouse_edge_scrolling_terrain( ctxt );
6802 const int scroll_timeout = get_option<int>( "EDGE_SCROLL" );
6803 const bool edge_scrolling = edge_scroll != tripoint_zero && scroll_timeout >= 0;
6804 if( edge_scrolling ) {
6805 action = ctxt.handle_input( scroll_timeout );
6806 } else {
6807 action = ctxt.handle_input();
6808 }
6809 if( ( action == "LEVEL_UP" || action == "LEVEL_DOWN" || action == "MOUSE_MOVE" ||
6810 ctxt.get_direction( action ) ) && ( ( select_zone && has_first_point ) || is_moving_zone ) ) {
6811 blink = true; // Always draw blink symbols when moving cursor
6812 } else if( action == "TIMEOUT" ) {
6813 blink = !blink;
6814 }
6815 if( action == "LIST_ITEMS" ) {
6817 } else if( action == "TOGGLE_FAST_SCROLL" ) {
6818 fast_scroll = !fast_scroll;
6819 } else if( action == "toggle_pixel_minimap" ) {
6821
6822 if( show_window && ui ) {
6823 ui->mark_resize();
6824 }
6825 } else if( action == "LEVEL_UP" || action == "LEVEL_DOWN" ) {
6826 if( !allow_zlev_move ) {
6827 continue;
6828 }
6829
6830 const int dz = ( action == "LEVEL_UP" ? 1 : -1 );
6831 lz = clamp( lz + dz, min_levz, max_levz );
6832 center.z = clamp( center.z + dz, min_levz, max_levz );
6833
6834 add_msg( m_debug, "levx: %d, levy: %d, levz: %d", get_levx(), get_levy(), center.z );
6835 u.view_offset.z = center.z - u.posz();
6837 } else if( action == "TRAVEL_TO" ) {
6838 if( !u.sees( lp ) ) {
6839 add_msg( _( "You can't see that destination." ) );
6840 continue;
6841 }
6842
6843 auto route = m.route( u.pos(), lp, u.get_pathfinding_settings(), u.get_path_avoid() );
6844 if( route.size() > 1 ) {
6845 route.pop_back();
6846 u.set_destination( route );
6847 } else {
6848 add_msg( m_info, _( "You can't travel there." ) );
6849 continue;
6850 }
6851 } else if( action == "debug_scent" || action == "debug_scent_type" ) {
6853 display_scent();
6854 }
6855 } else if( action == "debug_temp" ) {
6858 }
6859 } else if( action == "debug_lighting" ) {
6862 }
6863 } else if( action == "debug_transparency" ) {
6866 }
6867 } else if( action == "debug_radiation" ) {
6870 }
6871 } else if( action == "debug_submap_grid" ) {
6872 g->debug_submap_grid_overlay = !g->debug_submap_grid_overlay;
6873 } else if( action == "debug_hour_timer" ) {
6875 } else if( action == "EXTENDED_DESCRIPTION" ) {
6877 } else if( action == "CENTER" ) {
6878 center = u.pos();
6879 lp = u.pos();
6880 u.view_offset.z = 0;
6881 } else if( action == "MOUSE_MOVE" || action == "TIMEOUT" ) {
6882 // This block is structured this way so that edge scroll can work
6883 // whether the mouse is moving at the edge or simply stationary
6884 // at the edge. But even if edge scroll isn't in play, there's
6885 // other things for us to do here.
6886
6887 if( edge_scrolling ) {
6888 center += action == "MOUSE_MOVE" ? edge_scroll * 2 : edge_scroll;
6889 } else if( action == "MOUSE_MOVE" ) {
6890 const std::optional<tripoint> mouse_pos = ctxt.get_coordinates( w_terrain );
6891 if( mouse_pos ) {
6892 lx = mouse_pos->x;
6893 ly = mouse_pos->y;
6894 }
6895 }
6896 } else if( std::optional<tripoint> vec = ctxt.get_direction( action ) ) {
6897 if( fast_scroll ) {
6898 vec->x *= soffset;
6899 vec->y *= soffset;
6900 }
6901
6902 lx = lx + vec->x;
6903 ly = ly + vec->y;
6904 center.x = center.x + vec->x;
6905 center.y = center.y + vec->y;
6906 } else if( action == "throw_blind" ) {
6907 result.peek_action = PA_BLIND_THROW;
6908 } else if( action == "zoom_in" ) {
6909 center.x = lp.x;
6910 center.y = lp.y;
6911 zoom_in();
6913 } else if( action == "zoom_out" ) {
6914 center.x = lp.x;
6915 center.y = lp.y;
6916 zoom_out();
6918 }
6919 } while( action != "QUIT" && action != "CONFIRM" && action != "SELECT" && action != "TRAVEL_TO" &&
6920 action != "throw_blind" );
6921
6922 if( m.has_zlevels() && center.z != old_levz ) {
6923 m.invalidate_map_cache( old_levz );
6924 m.build_map_cache( old_levz );
6925 u.view_offset.z = 0;
6926 }
6927
6928 ctxt.reset_timeout();
6929 u.view_offset = prev_offset;
6930 zone_cb = nullptr;
6931 is_looking = false;
6932
6934 bVMonsterLookFire = true;
6935
6936 if( action == "CONFIRM" || action == "SELECT" ) {
6937 result.position = is_moving_zone ? zone_start : lp;
6938 }
6939
6940#if defined(TILES)
6941 if( is_moving_zone && get_zoom() != prev_tileset_zoom ) {
6942 // Reset the tileset zoom to the previous value
6943 set_zoom( prev_tileset_zoom );
6945 }
6946#endif
6947
6948 return result;
6949}
bool pixel_minimap_option
Whether to show the pixel minimap.
tripoint mouse_edge_scrolling_terrain(input_context &ctxt)
Used to implement mouse "edge scrolling".
Definition: game.cpp:2079
void set_zoom(int level)
Definition: game.cpp:7106
void draw_look_around_cursor(const tripoint &lp, const visibility_variables &cache)
Definition: game.cpp:5707
void extended_description(const tripoint &p)
Long description of (visible) things at tile.
void pre_print_all_tile_info(const tripoint &lp, const catacurses::window &w_info, int &line, int last_line, const visibility_variables &cache)
Definition: game.cpp:6586
int get_zoom() const
Definition: game.cpp:7118
const visibility_variables & get_visibility_variables_cache() const
Definition: map.cpp:5785
void invalidate_map_cache(const int zlev)
Definition: map.cpp:8970
std::vector< window_panel > & get_current_layout()
Definition: panels.cpp:2170
int square_dist(const coords::coord_point< Point, Origin, Scale > &loc1, const coords::coord_point< Point, Origin, Scale > &loc2)
Definition: coordinates.h:505
static shared_ptr_fast< game::draw_callback_t > create_zone_callback(const std::optional< tripoint > &zone_start, const std::optional< tripoint > &zone_end, const bool &zone_blink, const bool &zone_cursor, const bool &is_moving_zone=false)
Definition: game.cpp:3040
@ PA_BLIND_THROW
Definition: game.h:122
static constexpr int OVERMAP_HEIGHT
static constexpr int OVERMAP_DEPTH
int right_print(const catacurses::window &w, const int line, const int right_indent, const nc_color &FG, const std::string &text)
Definition: output.cpp:461

References _, action, add_draw_callback(), add_msg(), map::build_map_cache(), bVMonsterLookFire, c_green, c_light_gray, c_light_green, c_white, center, center_print(), clamp(), create_zone_callback(), display_lighting(), display_radiation(), display_scent(), display_temperature(), display_transparency(), draw_border(), draw_look_around_cursor(), extended_description(), fov_3d_z_range, g, input_context::get_action_name(), input_context::get_coordinates(), panel_manager::get_current_layout(), input_context::get_desc(), input_context::get_direction(), get_levx(), get_levy(), get_levz(), panel_manager::get_manager(), Character::get_path_avoid(), Character::get_pathfinding_settings(), map::get_visibility_variables_cache(), panel_manager::get_width_left(), get_zoom(), catacurses::getmaxy(), input_context::handle_input(), map::has_zlevels(), invalidate_main_ui_adaptor(), map::invalidate_map_cache(), is_looking, MAP_SHARING::isCompetitive(), MAP_SHARING::isDebugger(), list_items_monsters(), m, m_debug, m_info, mark_main_ui_adaptor_resize(), mouse_edge_scrolling_terrain(), mvwprintz(), catacurses::newwin(), OVERMAP_DEPTH, OVERMAP_HEIGHT, PA_BLIND_THROW, pixel_minimap_option, Character::pos(), Character::posz(), pre_print_all_tile_info(), ui_manager::redraw(), reenter_fullscreen(), input_context::register_action(), input_context::register_directions(), input_context::reset_timeout(), right_print(), map::route(), Character::sees(), Character::set_destination(), input_context::set_iso(), input_context::set_timeout(), set_zoom(), square_dist(), string_format(), temp_exit_fullscreen(), TERMX, TERMY, tileset_zoom, toggle_debug_hour_timer(), toggle_pixel_minimap(), tripoint_zero, u, map::update_visibility_cache(), use_tiles, player::view_offset, w_pixel_minimap, w_terrain, catacurses::werase(), catacurses::wnoutrefresh(), tripoint::x, tripoint::y, tripoint::z, zoom_in(), and zoom_out().

◆ look_debug()

std::optional< tripoint > game::look_debug ( )

Definition at line 5700 of file game.cpp.

5701{
5702 editmap edit;
5703 return edit.edit();
5704}
std::optional< tripoint > edit()
Definition: editmap.cpp:341

References editmap::edit().

◆ mark_main_ui_adaptor_resize()

void game::mark_main_ui_adaptor_resize ( ) const

Definition at line 2997 of file game.cpp.

2998{
3000 if( ui ) {
3001 ui->mark_resize();
3002 }
3003}

References main_ui_adaptor.

Referenced by handle_action(), look_around(), toggle_fullscreen(), and toggle_pixel_minimap().

◆ memorial()

memorial_logger & game::memorial ( )

Definition at line 2728 of file game.cpp.

2729{
2730 return *memorial_logger_ptr;
2731}

References memorial_logger_ptr.

Referenced by cleanup_at_end(), load(), save_player_data(), win(), win_screen(), and write_memorial_file().

◆ mon_info()

void game::mon_info ( const catacurses::window w,
int  hor_padding = 0 
)

Definition at line 3688 of file game.cpp.

3689{
3690 const monster_visible_info &mon_visible = u.get_mon_visible();
3691 const auto &unique_types = mon_visible.unique_types;
3692 const auto &unique_mons = mon_visible.unique_mons;
3693 const auto &dangerous = mon_visible.dangerous;
3694
3695 const int width = getmaxx( w ) - 2 * hor_padding;
3696 const int maxheight = getmaxy( w );
3697
3698 const int startrow = 0;
3699
3700 // Print the direction headings
3701 // Reminder:
3702 // 7 0 1 unique_types uses these indices;
3703 // 6 8 2 0-7 are provide by direction_from()
3704 // 5 4 3 8 is used for local monsters (for when we explain them below)
3705
3706 const std::array<std::string, 8> dir_labels = {{
3707 _( "North:" ), _( "NE:" ), _( "East:" ), _( "SE:" ),
3708 _( "South:" ), _( "SW:" ), _( "West:" ), _( "NW:" )
3709 }
3710 };
3711 std::array<int, 8> widths;
3712 for( int i = 0; i < 8; i++ ) {
3713 widths[i] = utf8_width( dir_labels[i] );
3714 }
3715 std::array<int, 8> xcoords;
3716 const std::array<int, 8> ycoords = {{ 0, 0, 1, 2, 2, 2, 1, 0 }};
3717 xcoords[0] = xcoords[4] = width / 3;
3718 xcoords[1] = xcoords[3] = xcoords[2] = ( width / 3 ) * 2;
3719 xcoords[5] = xcoords[6] = xcoords[7] = 0;
3720 //for the alignment of the 1,2,3 rows on the right edge
3721 xcoords[2] -= utf8_width( _( "East:" ) ) - utf8_width( _( "NE:" ) );
3722 for( int i = 0; i < 8; i++ ) {
3723 nc_color c = unique_types[i].empty() && unique_mons[i].empty() ? c_dark_gray
3724 : ( dangerous[i] ? c_light_red : c_light_gray );
3725 mvwprintz( w, point( xcoords[i] + hor_padding, ycoords[i] + startrow ), c, dir_labels[i] );
3726 }
3727
3728 // Print the symbols of all monsters in all directions.
3729 for( int i = 0; i < 8; i++ ) {
3730 point pr( xcoords[i] + widths[i] + 1, ycoords[i] + startrow );
3731
3732 // The list of symbols needs a space on each end.
3733 int symroom = ( width / 3 ) - widths[i] - 2;
3734 const int typeshere_npc = unique_types[i].size();
3735 const int typeshere_mon = unique_mons[i].size();
3736 const int typeshere = typeshere_mon + typeshere_npc;
3737 for( int j = 0; j < typeshere && j < symroom; j++ ) {
3738 nc_color c;
3739 std::string sym;
3740 if( symroom < typeshere && j == symroom - 1 ) {
3741 // We've run out of room!
3742 c = c_white;
3743 sym = "+";
3744 } else if( j < typeshere_npc ) {
3745 switch( unique_types[i][j]->get_attitude() ) {
3746 case NPCATT_KILL:
3747 c = c_red;
3748 break;
3749 case NPCATT_FOLLOW:
3750 c = c_light_green;
3751 break;
3752 default:
3753 c = c_pink;
3754 break;
3755 }
3756 sym = "@";
3757 } else {
3758 const mtype &mt = *unique_mons[i][j - typeshere_npc].first;
3759 c = mt.color;
3760 sym = mt.sym;
3761 }
3762 mvwprintz( w, pr, c, sym );
3763
3764 pr.x++;
3765 }
3766 }
3767
3768 // Now we print their full names!
3769 struct nearest_loc_and_cnt {
3770 int nearest_loc;
3771 int cnt;
3772 };
3773 std::map<const mtype *, nearest_loc_and_cnt> all_mons;
3774 for( int loc = 0; loc < 9; loc++ ) {
3775 for( const std::pair<const mtype *, int> &mon : unique_mons[loc] ) {
3776 const auto mon_it = all_mons.find( mon.first );
3777 if( mon_it == all_mons.end() ) {
3778 all_mons.emplace( mon.first, nearest_loc_and_cnt{ loc, mon.second } );
3779 } else {
3780 // 8 being the nearest location (local monsters)
3781 mon_it->second.nearest_loc = std::max( mon_it->second.nearest_loc, loc );
3782 mon_it->second.cnt += mon.second;
3783 }
3784 }
3785 }
3786 std::vector<std::pair<const mtype *, int>> mons_at[9];
3787 for( const std::pair<const mtype *const, nearest_loc_and_cnt> &mon : all_mons ) {
3788 mons_at[mon.second.nearest_loc].emplace_back( mon.first, mon.second.cnt );
3789 }
3790
3791 // Start printing monster names on row 4. Rows 0-2 are for labels, and row 3
3792 // is blank.
3793 point pr( hor_padding, 4 + startrow );
3794
3795 // Print monster names, starting with those at location 8 (nearby).
3796 for( int j = 8; j >= 0 && pr.y < maxheight; j-- ) {
3797 // Separate names by some number of spaces (more for local monsters).
3798 int namesep = ( j == 8 ? 2 : 1 );
3799 for( const std::pair<const mtype *, int> &mon : mons_at[j] ) {
3800 const mtype *const type = mon.first;
3801 const int count = mon.second;
3802 if( pr.y >= maxheight ) {
3803 // no space to print to anyway
3804 break;
3805 }
3806
3807 const mtype &mt = *type;
3808 std::string name = mt.nname( count );
3809 // Some languages don't have plural forms, but we want to always
3810 // omit 1.
3811 if( count != 1 ) {
3812 name = string_format( pgettext( "monster count and name", "%1$d %2$s" ),
3813 count, name );
3814 }
3815
3816 // Move to the next row if necessary. (The +2 is for the "Z ").
3817 if( pr.x + 2 + utf8_width( name ) >= width ) {
3818 pr.y++;
3819 pr.x = hor_padding;
3820 }
3821
3822 if( pr.y < maxheight ) { // Don't print if we've overflowed
3823 mvwprintz( w, pr, mt.color, mt.sym );
3824 pr.x += 2; // symbol and space
3825 nc_color danger = c_dark_gray;
3826 if( mt.difficulty >= 30 ) {
3827 danger = c_red;
3828 } else if( mt.difficulty >= 16 ) {
3829 danger = c_light_red;
3830 } else if( mt.difficulty >= 8 ) {
3831 danger = c_white;
3832 } else if( mt.agro > 0 ) {
3833 danger = c_light_gray;
3834 }
3835 mvwprintz( w, pr, danger, name );
3836 pr.x += utf8_width( name ) + namesep;
3837 }
3838 }
3839 }
3840}
@ NPCATT_KILL
Definition: npc.h:91
@ NPCATT_FOLLOW
Definition: npc.h:84
std::vector< std::pair< const mtype *, int > > unique_mons[9]
Definition: avatar.h:48
bool dangerous[8]
Definition: avatar.h:51
std::vector< npc * > unique_types[9]
Definition: avatar.h:47
Definition: mtype.h:209
std::string sym
UTF-8 encoded symbol, should be exactly one cell wide.
Definition: mtype.h:257
nc_color color
Definition: mtype.h:262
int difficulty
Definition: mtype.h:268
int agro
e.g.
Definition: mtype.h:273

References _, mtype::agro, c, c_dark_gray, c_light_gray, c_light_green, c_light_red, c_pink, c_red, c_white, mtype::color, detail::count(), monster_visible_info::dangerous, mtype::difficulty, avatar::get_mon_visible(), catacurses::getmaxx(), catacurses::getmaxy(), mvwprintz(), om_direction::name(), mtype::nname(), NPCATT_FOLLOW, NPCATT_KILL, pgettext(), string_format(), mtype::sym, type, u, monster_visible_info::unique_mons, monster_visible_info::unique_types, utf8_width(), point::x, and point::y.

◆ mon_info_update()

void game::mon_info_update ( )

Definition at line 3842 of file game.cpp.

3843{
3844 int newseen = 0;
3845 const int safe_proxy_dist = get_option<int>( "SAFEMODEPROXIMITY" );
3846 const int iProxyDist = ( safe_proxy_dist <= 0 ) ? MAX_VIEW_DISTANCE :
3847 safe_proxy_dist;
3848
3849 monster_visible_info &mon_visible = u.get_mon_visible();
3850 auto &new_seen_mon = mon_visible.new_seen_mon;
3851 auto &unique_types = mon_visible.unique_types;
3852 auto &unique_mons = mon_visible.unique_mons;
3853 auto &dangerous = mon_visible.dangerous;
3854
3855 // 7 0 1 unique_types uses these indices;
3856 // 6 8 2 0-7 are provide by direction_from()
3857 // 5 4 3 8 is used for local monsters (for when we explain them below)
3858 for( auto &t : unique_types ) {
3859 t.clear();
3860 }
3861 for( auto &m : unique_mons ) {
3862 m.clear();
3863 }
3864 std::fill( dangerous, dangerous + 8, false );
3865
3866 const tripoint view = u.pos() + u.view_offset;
3867 new_seen_mon.clear();
3868
3869 // TODO: no reason to have it static here
3870 static time_point previous_turn = calendar::start_of_cataclysm;
3871 const time_duration sm_ignored_time = time_duration::from_turns(
3872 get_option<int>( "SAFEMODEIGNORETURNS" ) );
3873
3875 monster *m = dynamic_cast<monster *>( c );
3876 npc *p = dynamic_cast<npc *>( c );
3877 const direction dir_to_mon = direction_from( view.xy(), point( c->posx(), c->posy() ) );
3878 const int mx = POSX + ( c->posx() - view.x );
3879 const int my = POSY + ( c->posy() - view.y );
3880 int index = 8;
3881 if( !is_valid_in_w_terrain( point( mx, my ) ) ) {
3882 // for compatibility with old code, see diagram below, it explains the values for index,
3883 // also might need revisiting one z-levels are in.
3884 switch( dir_to_mon ) {
3888 index = 7;
3889 break;
3891 case direction::NORTH:
3893 index = 0;
3894 break;
3898 index = 1;
3899 break;
3901 case direction::WEST:
3903 index = 6;
3904 break;
3906 case direction::CENTER:
3908 index = 8;
3909 break;
3911 case direction::EAST:
3913 index = 2;
3914 break;
3918 index = 5;
3919 break;
3921 case direction::SOUTH:
3923 index = 4;
3924 break;
3928 index = 3;
3929 break;
3930 }
3931 }
3932
3933 rule_state safemode_state = RULE_NONE;
3934 const bool safemode_empty = get_safemode().empty();
3935
3936 if( m != nullptr ) {
3937 //Safemode monster check
3938 monster &critter = *m;
3939
3940 const monster_attitude matt = critter.attitude( &u );
3941 const int mon_dist = rl_dist( u.pos(), critter.pos() );
3942 safemode_state = get_safemode().check_monster( critter.name(), critter.attitude_to( u ), mon_dist );
3943
3944 if( ( !safemode_empty && safemode_state == RULE_BLACKLISTED ) || ( safemode_empty &&
3945 ( MATT_ATTACK == matt || MATT_FOLLOW == matt ) ) ) {
3946 if( index < 8 && critter.sees( g->u ) ) {
3947 dangerous[index] = true;
3948 }
3949
3950 if( !safemode_empty || mon_dist <= iProxyDist ) {
3951 bool passmon = false;
3952 if( critter.ignoring > 0 ) {
3953 if( safe_mode != SAFE_MODE_ON ) {
3954 critter.ignoring = 0;
3955 } else if( ( sm_ignored_time == 0_seconds || ( critter.lastseen_turn &&
3956 *critter.lastseen_turn > calendar::turn - sm_ignored_time ) ) &&
3957 ( mon_dist > critter.ignoring / 2 || mon_dist < 6 ) ) {
3958 passmon = true;
3959 }
3960 critter.lastseen_turn = calendar::turn;
3961 }
3962
3963 if( !passmon ) {
3964 newseen++;
3965 new_seen_mon.push_back( shared_from( critter ) );
3966 }
3967 }
3968 }
3969
3970 std::vector<std::pair<const mtype *, int>> &vec = unique_mons[index];
3971 const auto mon_it = std::find_if( vec.begin(), vec.end(),
3972 [&]( const std::pair<const mtype *, int> &elem ) {
3973 return elem.first == critter.type;
3974 } );
3975 if( mon_it == vec.end() ) {
3976 vec.emplace_back( critter.type, 1 );
3977 } else {
3978 mon_it->second++;
3979 }
3980 } else if( p != nullptr ) {
3981 //Safe mode NPC check
3982
3983 const int npc_dist = rl_dist( u.pos(), p->pos() );
3984 safemode_state = get_safemode().check_monster( get_safemode().npc_type_name(), p->attitude_to( u ),
3985 npc_dist );
3986
3987 if( ( !safemode_empty && safemode_state == RULE_BLACKLISTED ) || ( safemode_empty &&
3988 p->get_attitude() == NPCATT_KILL ) ) {
3989 if( !safemode_empty || npc_dist <= iProxyDist ) {
3990 newseen++;
3991 }
3992 }
3993 unique_types[index].push_back( p );
3994 }
3995 }
3996
3997 if( newseen > mostseen ) {
3998 if( newseen - mostseen == 1 ) {
3999 if( !new_seen_mon.empty() ) {
4000 monster &critter = *new_seen_mon.back();
4002 string_format( _( "%s spotted!" ), critter.name() ) );
4003 if( u.has_trait( trait_id( "M_DEFENDER" ) ) && critter.type->in_species( PLANT ) ) {
4004 add_msg( m_warning, _( "We have detected a %s - an enemy of the Mycus!" ), critter.name() );
4006 u.add_effect( effect_adrenaline_mycus, 30_minutes );
4007 } else if( u.get_effect_int( effect_adrenaline_mycus ) == 1 ) {
4008 // Triffids present. We ain't got TIME to adrenaline comedown!
4009 u.add_effect( effect_adrenaline_mycus, 15_minutes );
4010 u.mod_pain( 3 ); // Does take it out of you, though
4011 add_msg( m_info, _( "Our fibers strain with renewed wrath!" ) );
4012 }
4013 }
4014 } else {
4015 //Hostile NPC
4017 _( "Hostile survivor spotted!" ) );
4018 }
4019 } else {
4021 }
4023 if( safe_mode == SAFE_MODE_ON ) {
4025 }
4026 } else if( calendar::turn > previous_turn && get_option<bool>( "AUTOSAFEMODE" ) &&
4027 newseen == 0 ) { // Auto-safe mode, but only if it's a new turn
4028 turnssincelastmon += to_turns<int>( calendar::turn - previous_turn );
4029 if( turnssincelastmon >= get_option<int>( "AUTOSAFEMODETURNS" ) && safe_mode == SAFE_MODE_OFF ) {
4031 add_msg( m_info, _( "Safe mode ON!" ) );
4032 }
4033 }
4034
4035 if( newseen == 0 && safe_mode == SAFE_MODE_STOP ) {
4037 }
4038
4039 previous_turn = calendar::turn;
4040 mostseen = newseen;
4041}
int get_effect_int(const efftype_id &eff_id, body_part bp=num_bp) const
Returns the intensity of the matching effect.
Definition: creature.cpp:1291
virtual bool sees(const Creature &critter) const
The functions check whether this creature can see the target.
Definition: creature.cpp:205
bool cancel_activity_or_ignore_query(distraction_type type, const std::string &text)
Asks if the player wants to cancel their activity and if so cancels it.
Definition: game.cpp:1700
monster_attitude attitude(const Character *u=nullptr) const
Definition: monster.cpp:1098
std::optional< time_point > lastseen_turn
Definition: monster.h:506
Attitude attitude_to(const Creature &other) const override
Attitude (of this creature) towards another creature.
Definition: npc.cpp:2081
rule_state check_monster(const std::string &creature_name_in, Creature::Attitude attitude_in, int proximity_in) const
bool empty() const
rule_state
Definition: enums.h:51
@ RULE_NONE
Definition: enums.h:52
static const species_id PLANT("PLANT")
static const efftype_id effect_adrenaline_mycus("adrenaline_mycus")
bool is_valid_in_w_terrain(point p)
Definition: game.cpp:290
static constexpr int MAPSIZE_X
monster_attitude
Definition: monster.h:55
@ MATT_FOLLOW
Definition: monster.h:61
@ MATT_ATTACK
Definition: monster.h:62
FMT_NOINLINE OutputIt fill(OutputIt it, size_t n, const fill_t< Char > &fill)
bool in_species(const species_id &spec) const
Definition: mtype.cpp:122

References _, ABOVECENTER, ABOVEEAST, ABOVENORTH, ABOVENORTHEAST, ABOVENORTHWEST, ABOVESOUTH, ABOVESOUTHEAST, ABOVESOUTHWEST, ABOVEWEST, Creature::add_effect(), add_msg(), monster::attitude(), monster::attitude_to(), npc::attitude_to(), BELOWCENTER, BELOWEAST, BELOWNORTH, BELOWNORTHEAST, BELOWNORTHWEST, BELOWSOUTH, BELOWSOUTHEAST, BELOWSOUTHWEST, BELOWWEST, c, cancel_activity_or_ignore_query(), CENTER, safemode::check_monster(), monster_visible_info::dangerous, direction_from(), EAST, effect_adrenaline_mycus, safemode::empty(), detail::fill(), time_duration::from_turns(), g, npc::get_attitude(), Creature::get_effect_int(), avatar::get_mon_visible(), get_safemode(), Character::get_visible_creatures(), Creature::has_effect(), Character::has_trait(), hostile_spotted_far, monster::ignoring, mtype::in_species(), is_valid_in_w_terrain(), monster::lastseen_turn, m, m_info, m_warning, MAPSIZE_X, MATT_ATTACK, MATT_FOLLOW, MAX_VIEW_DISTANCE, Character::mod_pain(), mostseen, monster::name(), monster_visible_info::new_seen_mon, NORTH, NORTHEAST, NORTHWEST, NPCATT_KILL, PLANT, Character::pos(), monster::pos(), POSX, POSY, rl_dist(), RULE_BLACKLISTED, RULE_NONE, safe_mode, SAFE_MODE_OFF, SAFE_MODE_ON, SAFE_MODE_STOP, Creature::sees(), set_safe_mode(), shared_from(), SOUTH, SOUTHEAST, SOUTHWEST, calendar::start_of_cataclysm, string_format(), calendar::turn, turnssincelastmon, monster::type, u, monster_visible_info::unique_mons, monster_visible_info::unique_types, player::view_offset, WEST, tripoint::x, tripoint::xy(), and tripoint::y.

Referenced by do_turn().

◆ monmove()

void game::monmove ( )
private

Definition at line 4078 of file game.cpp.

4079{
4080 cleanup_dead();
4081
4082 for( monster &critter : all_monsters() ) {
4083 // Critters in impassable tiles get pushed away, unless it's not impassable for them
4084 if( !critter.is_dead() && m.impassable( critter.pos() ) && !critter.can_move_to( critter.pos() ) ) {
4085 std::string msg = string_format( "%s can't move to its location! %s %s", critter.name(),
4086 critter.pos().to_string(), m.tername( critter.pos() ) );
4087 dbg( DL::Error ) << msg;
4088 add_msg( m_debug, msg );
4089 bool okay = false;
4090 for( const tripoint &dest : m.points_in_radius( critter.pos(), 3 ) ) {
4091 if( critter.can_move_to( dest ) && is_empty( dest ) ) {
4092 critter.setpos( dest );
4093 okay = true;
4094 break;
4095 }
4096 }
4097 if( !okay ) {
4098 // die of "natural" cause (overpopulation is natural)
4099 critter.die( nullptr );
4100 }
4101 }
4102
4103 if( !critter.is_dead() ) {
4104 critter.process_items();
4105 }
4106
4107 if( !critter.is_dead() ) {
4108 critter.process_turn();
4109 }
4110
4111 m.creature_in_field( critter );
4112 if( calendar::once_every( 1_days ) ) {
4113 if( critter.has_flag( MF_MILKABLE ) ) {
4114 critter.refill_udders();
4115 }
4116 critter.try_reproduce();
4117 }
4118 while( critter.moves > 0 && !critter.is_dead() && !critter.has_effect( effect_ridden ) ) {
4119 critter.made_footstep = false;
4120 // Controlled critters don't make their own plans
4121 if( !critter.has_effect( effect_ai_controlled ) ) {
4122 // Formulate a path to follow
4123 critter.plan();
4124 }
4125 critter.move(); // Move one square, possibly hit u
4126 critter.process_triggers();
4127 m.creature_in_field( critter );
4128 }
4129
4130 const bionic_id bio_alarm( "bio_alarm" );
4131 if( !critter.is_dead() &&
4132 u.has_active_bionic( bio_alarm ) &&
4133 u.get_power_level() >= bio_alarm->power_trigger &&
4134 rl_dist( u.pos(), critter.pos() ) <= 5 &&
4135 !critter.is_hallucination() ) {
4136 u.mod_power_level( -bio_alarm->power_trigger );
4137 add_msg( m_warning, _( "Your motion alarm goes off!" ) );
4139 _( "Your motion alarm goes off!" ) );
4140 if( u.has_effect( efftype_id( "sleep" ) ) ) {
4141 u.wake_up();
4142 }
4143 }
4144 }
4145
4146 cleanup_dead();
4147
4148 // The remaining monsters are all alive, but may be outside of the reality bubble.
4149 // If so, despawn them. This is not the same as dying, they will be stored for later and the
4150 // monster::die function is not called.
4151 for( monster &critter : all_monsters() ) {
4152 if( critter.posx() < 0 - ( MAPSIZE_X ) / 6 ||
4153 critter.posy() < 0 - ( MAPSIZE_Y ) / 6 ||
4154 critter.posx() > ( MAPSIZE_X * 7 ) / 6 ||
4155 critter.posy() > ( MAPSIZE_Y * 7 ) / 6 ) {
4156 despawn_monster( critter );
4157 }
4158 }
4159
4160 // Now, do active NPCs.
4161 for( npc &guy : g->all_npcs() ) {
4162 int turns = 0;
4163 if( guy.is_mounted() ) {
4164 guy.check_mount_is_spooked();
4165 }
4166 m.creature_in_field( guy );
4167 if( !guy.has_effect( effect_npc_suspend ) ) {
4168 guy.process_turn();
4169 }
4170 while( !guy.is_dead() && guy.moves > 0 && turns < 10 &&
4171 ( !guy.in_sleep_state() || guy.activity.id() == ACT_OPERATION )
4172 ) {
4173 int moves = guy.moves;
4174 guy.move();
4175 if( moves == guy.moves ) {
4176 // Count every time we exit npc::move() without spending any moves.
4177 turns++;
4178 }
4179
4180 // Turn on debug mode when in infinite loop
4181 // It has to be done before the last turn, otherwise
4182 // there will be no meaningful debug output.
4183 if( turns == 9 ) {
4184 debugmsg( "NPC %s entered infinite loop. Turning on debug mode",
4185 guy.name );
4186 debug_mode = true;
4187 }
4188 }
4189
4190 // If we spun too long trying to decide what to do (without spending moves),
4191 // Invoke cognitive suspension to prevent an infinite loop.
4192 if( turns == 10 ) {
4193 add_msg( _( "%s faints!" ), guy.name );
4194 guy.reboot();
4195 }
4196
4197 if( !guy.is_dead() ) {
4198 guy.npc_update_body();
4199 }
4200 }
4201 cleanup_dead();
4202}
void mod_power_level(const units::energy &npower)
Definition: character.cpp:1925
units::energy get_power_level() const
Definition: character.cpp:1905
void wake_up()
Definition: avatar.cpp:959
static const activity_id ACT_OPERATION("ACT_OPERATION")
static const efftype_id effect_npc_suspend("npc_suspend")
static const efftype_id effect_ai_controlled("ai_controlled")
static constexpr int MAPSIZE_Y
@ MF_MILKABLE
Definition: mtype.h:168

References _, ACT_OPERATION, add_msg(), alert, all_monsters(), cancel_activity_or_ignore_query(), cleanup_dead(), map::creature_in_field(), dbg, debug_mode, debugmsg, despawn_monster(), anonymous_namespace{iexamine_elevator.cpp}::elevator::dest(), effect_ai_controlled, effect_npc_suspend, effect_ridden, Error, g, Character::get_power_level(), Character::has_active_bionic(), Creature::has_effect(), map::impassable(), is_empty(), m, m_debug, m_warning, MAPSIZE_X, MAPSIZE_Y, MF_MILKABLE, Character::mod_power_level(), calendar::once_every(), map::points_in_radius(), Character::pos(), bionic_data::power_trigger, rl_dist(), string_format(), map::tername(), u, and avatar::wake_up().

Referenced by do_turn().

◆ mouse_edge_scrolling()

std::pair< tripoint, tripoint > game::mouse_edge_scrolling ( input_context ctxt,
int  speed,
const tripoint last,
bool  iso 
)
private

Definition at line 2026 of file game.cpp.

2028{
2029 const int rate = get_option<int>( "EDGE_SCROLL" );
2030 auto ret = std::make_pair( tripoint_zero, last );
2031 if( rate == -1 ) {
2032 // Fast return when the option is disabled.
2033 return ret;
2034 }
2035 // Ensure the parameters are used even if the #if below is false
2036 ( void ) ctxt;
2037 ( void ) speed;
2038 ( void ) iso;
2039#if (defined TILES || defined _WIN32 || defined WINDOWS)
2040 auto now = std::chrono::steady_clock::now();
2041 if( now < last_mouse_edge_scroll + std::chrono::milliseconds( rate ) ) {
2042 return ret;
2043 } else {
2045 }
2046 const input_event event = ctxt.get_raw_input();
2047 if( event.type == CATA_INPUT_MOUSE ) {
2048 const point threshold( projected_window_width() / 100, projected_window_height() / 100 );
2049 if( event.mouse_pos.x <= threshold.x ) {
2050 ret.first.x -= speed;
2051 if( iso ) {
2052 ret.first.y -= speed;
2053 }
2054 } else if( event.mouse_pos.x >= projected_window_width() - threshold.x ) {
2055 ret.first.x += speed;
2056 if( iso ) {
2057 ret.first.y += speed;
2058 }
2059 }
2060 if( event.mouse_pos.y <= threshold.y ) {
2061 ret.first.y -= speed;
2062 if( iso ) {
2063 ret.first.x += speed;
2064 }
2065 } else if( event.mouse_pos.y >= projected_window_height() - threshold.y ) {
2066 ret.first.y += speed;
2067 if( iso ) {
2068 ret.first.x -= speed;
2069 }
2070 }
2071 ret.second = ret.first;
2072 } else if( event.type == CATA_INPUT_TIMEOUT ) {
2073 ret.first = ret.second;
2074 }
2075#endif
2076 return ret;
2077}
@ CATA_INPUT_TIMEOUT
Definition: input.h:77
@ CATA_INPUT_MOUSE
Definition: input.h:80

References CATA_INPUT_MOUSE, CATA_INPUT_TIMEOUT, input_context::get_raw_input(), iso, last, last_mouse_edge_scroll, cata::hash64_detail::ret, tripoint_zero, point::x, and point::y.

Referenced by mouse_edge_scrolling_overmap(), and mouse_edge_scrolling_terrain().

◆ mouse_edge_scrolling_overmap()

tripoint game::mouse_edge_scrolling_overmap ( input_context ctxt)

This variant is suitable for the overmap.

Definition at line 2088 of file game.cpp.

2089{
2090 // overmap has no iso mode
2094 return ret.first;
2095}
std::pair< tripoint, tripoint > mouse_edge_scrolling(input_context &ctxt, int speed, const tripoint &last, bool iso)
Definition: game.cpp:2026
tripoint last_mouse_edge_scroll_vector_terrain
Definition: game.h:1068
tripoint last_mouse_edge_scroll_vector_overmap
Definition: game.h:1069

References last_mouse_edge_scroll_vector_overmap, last_mouse_edge_scroll_vector_terrain, mouse_edge_scrolling(), cata::hash64_detail::ret, and tripoint_zero.

◆ mouse_edge_scrolling_terrain()

tripoint game::mouse_edge_scrolling_terrain ( input_context ctxt)

Used to implement mouse "edge scrolling".

Returns a tripoint which is a vector of the resulting "move", i.e. (0, 0, 0) if the mouse is not at the edge of the screen, otherwise some (x, y, 0) depending on which edges are hit. This variant adjust scrolling speed according to zoom level, making it suitable when viewing the "terrain".

Definition at line 2079 of file game.cpp.

References DEFAULT_TILESET_ZOOM, last_mouse_edge_scroll_vector_overmap, last_mouse_edge_scroll_vector_terrain, mouse_edge_scrolling(), cata::hash64_detail::ret, tile_iso, tileset_zoom, and tripoint_zero.

Referenced by look_around().

◆ move_save_to_graveyard()

void game::move_save_to_graveyard ( const std::string &  dirname)
private

Definition at line 2471 of file game.cpp.

2472{
2473 const std::string save_dir = get_world_base_save_path();
2474 const std::string graveyard_dir = PATH_INFO::graveyarddir() + "/";
2475 const std::string graveyard_save_dir = graveyard_dir + dirname + "/";
2476 const std::string &prefix = base64_encode( u.get_save_id() ) + ".";
2477
2478 if( !assure_dir_exist( graveyard_dir ) ) {
2479 debugmsg( "could not create graveyard path '%s'", graveyard_dir );
2480 }
2481
2482 if( !assure_dir_exist( graveyard_save_dir ) ) {
2483 debugmsg( "could not create graveyard path '%s'", graveyard_save_dir );
2484 }
2485
2486 const auto save_files = get_files_from_path( prefix, save_dir );
2487 if( save_files.empty() ) {
2488 debugmsg( "could not find save files in '%s'", save_dir );
2489 }
2490
2491 for( const auto &src_path : save_files ) {
2492 const std::string dst_path = graveyard_save_dir +
2493 src_path.substr( src_path.rfind( '/' ), std::string::npos );
2494
2495 if( rename_file( src_path, dst_path ) ) {
2496 continue;
2497 }
2498
2499 debugmsg( "could not rename file '%s' to '%s'", src_path, dst_path );
2500
2501 if( remove_file( src_path ) ) {
2502 continue;
2503 }
2504
2505 debugmsg( "could not remove file '%s'", src_path );
2506 }
2507}
bool remove_file(const std::string &path)
Remove a file.
Definition: filesystem.cpp:89
bool assure_dir_exist(const std::string &path)
Create directory if it does not exist.
Definition: filesystem.cpp:48
bool rename_file(const std::string &old_path, const std::string &new_path)
Rename a file, overwriting the target.
Definition: filesystem.cpp:105
std::vector< std::string > get_files_from_path(const std::string &pattern, const std::string &root_path, const bool recursive_search, const bool match_extension)
Returns a vector of files or directories matching pattern at root_path.
Definition: filesystem.cpp:366
std::string graveyarddir()
Definition: path_info.cpp:202

References assure_dir_exist(), base64_encode(), debugmsg, get_files_from_path(), avatar::get_save_id(), get_world_base_save_path(), PATH_INFO::graveyarddir(), prefix, remove_file(), rename_file(), and u.

Referenced by cleanup_at_end().

◆ moving_vehicle_dismount()

void game::moving_vehicle_dismount ( const tripoint dest_loc)

Handles players exiting from moving vehicles.

Definition at line 5152 of file game.cpp.

5153{
5154 const optional_vpart_position vp = m.veh_at( u.pos() );
5155 if( !vp ) {
5156 debugmsg( "Tried to exit non-existent vehicle." );
5157 return;
5158 }
5159 vehicle *const veh = &vp->vehicle();
5160 if( u.pos() == dest_loc ) {
5161 debugmsg( "Need somewhere to dismount towards." );
5162 return;
5163 }
5164 tileray ray( dest_loc.xy() + point( -u.posx(), -u.posy() ) );
5165 // TODO:: make dir() const correct!
5166 const units::angle d = ray.dir();
5167 add_msg( _( "You dive from the %s." ), veh->name );
5168 m.unboard_vehicle( u.pos() );
5169 u.moves -= 200;
5170 // Dive three tiles in the direction of tox and toy
5171 fling_creature( &u, d, 30, true );
5172 // Hit the ground according to vehicle speed
5173 if( !m.has_flag( "SWIMMABLE", u.pos() ) ) {
5174 if( veh->velocity > 0 ) {
5175 fling_creature( &u, veh->face.dir(), veh->velocity / static_cast<float>( 100 ) );
5176 } else {
5177 fling_creature( &u, veh->face.dir() + 180_degrees,
5178 -( veh->velocity ) / static_cast<float>( 100 ) );
5179 }
5180 }
5181}
void fling_creature(Creature *c, const units::angle &dir, float flvel, bool controlled=false)
Flings the input creature in the given direction.
Definition: game.cpp:9799

References _, add_msg(), debugmsg, tileray::dir(), vehicle::face, fling_creature(), map::has_flag(), m, Creature::moves, vehicle::name, Character::pos(), Character::posx(), Character::posy(), u, map::unboard_vehicle(), map::veh_at(), vehicle::velocity, and tripoint::xy().

◆ natural_light_level()

float game::natural_light_level ( int  zlev) const

Definition at line 3507 of file game.cpp.

3508{
3509 // ignore while underground or above limits
3510 if( zlev > OVERMAP_HEIGHT || zlev < 0 ) {
3511 return LIGHT_AMBIENT_MINIMAL;
3512 }
3513
3514 if( latest_lightlevels[zlev] > -std::numeric_limits<float>::max() ) {
3515 // Already found the light level for now?
3516 return latest_lightlevels[zlev];
3517 }
3518
3519 float ret = LIGHT_AMBIENT_MINIMAL;
3520
3521 // Sunlight/moonlight related stuff
3523 if( !weather.lightning_active ) {
3525 } else {
3526 // Recent lightning strike has lit the area
3528 }
3529
3531
3532 // Artifact light level changes here. Even though some of these only have an effect
3533 // aboveground it is cheaper performance wise to simply iterate through the entire
3534 // list once instead of twice.
3535 float mod_ret = -1;
3536 // Each artifact change does std::max(mod_ret, new val) since a brighter end value
3537 // will trump a lower one.
3538 if( const timed_event *e = timed_events.get( TIMED_EVENT_DIM ) ) {
3539 // TIMED_EVENT_DIM slowly dims the natural sky level, then relights it.
3540 const time_duration left = e->when - calendar::turn;
3541 // TIMED_EVENT_DIM has an occurrence date of turn + 50, so the first 25 dim it,
3542 if( left > 25_turns ) {
3543 mod_ret = std::max( static_cast<double>( mod_ret ), ( ret * ( left - 25_turns ) ) / 25_turns );
3544 // and the last 25 scale back towards normal.
3545 } else {
3546 mod_ret = std::max( static_cast<double>( mod_ret ), ( ret * ( 25_turns - left ) ) / 25_turns );
3547 }
3548 }
3550 // TIMED_EVENT_ARTIFACT_LIGHT causes everywhere to become as bright as day.
3551 mod_ret = std::max<float>( ret, default_daylight_level() );
3552 }
3553 // If we had a changed light level due to an artifact event then it overwrites
3554 // the natural light level.
3555 if( mod_ret > -1 ) {
3556 ret = mod_ret;
3557 }
3558
3559 // Cap everything to our minimum light level
3560 ret = std::max<float>( LIGHT_AMBIENT_MINIMAL, ret );
3561
3562 latest_lightlevels[zlev] = ret;
3563
3564 return ret;
3565}
double default_daylight_level()
How much light is provided in full daylight.
Definition: calendar.cpp:62
float sunlight(const time_point &p, const bool vision)
Returns the current sunlight or moonlight level through the preceding functions.
Definition: calendar.cpp:199
std::array< float, OVERMAP_LAYERS > latest_lightlevels
Definition: game.h:1041
bool queued(timed_event_type type) const
timed_event * get(timed_event_type type)
weather_type_id weather_id
Definition: weather.h:193
static constexpr float LIGHT_AMBIENT_MINIMAL
Definition: lightmap.h:12
@ TIMED_EVENT_DIM
Definition: timed_event.h:22
@ TIMED_EVENT_ARTIFACT_LIGHT
Definition: timed_event.h:23

References default_daylight_level(), timed_event_manager::get(), get_weather, latest_lightlevels, left, LIGHT_AMBIENT_MINIMAL, weather_type::light_modifier, OVERMAP_HEIGHT, timed_event_manager::queued(), cata::hash64_detail::ret, sunlight(), TIMED_EVENT_ARTIFACT_LIGHT, TIMED_EVENT_DIM, timed_events, calendar::turn, and weather_manager::weather_id.

Referenced by light_level().

◆ npc_menu()

bool game::npc_menu ( npc who)

Returns true if the menu handled stuff and player shouldn't do anything else.

Perception slightly increases precision when examining NPCs' wounds Firstaid increases precision when examining NPCs' wounds

Definition at line 5283 of file game.cpp.

5284{
5285 enum choices : int {
5286 talk = 0,
5287 swap_pos,
5288 push,
5289 examine_wounds,
5290 use_item,
5291 sort_armor,
5292 attack,
5293 disarm,
5294 steal
5295 };
5296
5297 const bool obeys = debug_mode || ( who.is_player_ally() && !who.in_sleep_state() );
5298
5299 uilist amenu;
5300
5301 amenu.text = string_format( _( "What to do with %s?" ), who.disp_name() );
5302 amenu.addentry( talk, true, 't', _( "Talk" ) );
5303 amenu.addentry( swap_pos, obeys && !who.is_mounted() &&
5304 !u.is_mounted(), 's', _( "Swap positions" ) );
5305 amenu.addentry( push, obeys && !who.is_mounted(), 'p', _( "Push away" ) );
5306 amenu.addentry( examine_wounds, true, 'w', _( "Examine wounds" ) );
5307 amenu.addentry( use_item, true, 'i', _( "Use item on" ) );
5308 amenu.addentry( sort_armor, obeys, 'r', _( "Sort armor" ) );
5309 amenu.addentry( attack, true, 'a', _( "Attack" ) );
5310 if( !who.is_player_ally() ) {
5311 amenu.addentry( disarm, who.is_armed(), 'd', _( "Disarm" ) );
5312 amenu.addentry( steal, !who.is_enemy(), 'S', _( "Steal" ) );
5313 }
5314
5315 amenu.query();
5316
5317 const int choice = amenu.ret;
5318 if( choice == talk ) {
5319 who.talk_to_u();
5320 } else if( choice == swap_pos ) {
5321 if( !prompt_dangerous_tile( who.pos() ) ) {
5322 return true;
5323 }
5324 // TODO: Make NPCs protest when displaced onto dangerous crap
5325 add_msg( _( "You swap places with %s." ), who.name );
5326 swap_critters( u, who );
5327 // TODO: Make that depend on stuff
5328 u.mod_moves( -200 );
5329 } else if( choice == push ) {
5330 // TODO: Make NPCs protest when displaced onto dangerous crap
5331 tripoint oldpos = who.pos();
5332 who.move_away_from( u.pos(), true );
5333 u.mod_moves( -20 );
5334 if( oldpos != who.pos() ) {
5335 add_msg( _( "%s moves out of the way." ), who.name );
5336 } else {
5337 add_msg( m_warning, _( "%s has nowhere to go!" ), who.name );
5338 }
5339 } else if( choice == examine_wounds ) {
5340 ///\EFFECT_PER slightly increases precision when examining NPCs' wounds
5341
5342 ///\EFFECT_FIRSTAID increases precision when examining NPCs' wounds
5343 const bool precise = u.get_skill_level( skill_firstaid ) * 4 + u.per_cur >= 20;
5344 who.body_window( _( "Limbs of: " ) + who.disp_name(), true, precise, 0, 0, 0, 0.0f, 0.0f, 0.0f,
5345 0.0f, 0.0f );
5346 } else if( choice == use_item ) {
5347 static const std::string heal_string( "heal" );
5348 const auto will_accept = []( const item & it ) {
5349 const auto use_fun = it.get_use( heal_string );
5350 if( use_fun == nullptr ) {
5351 return false;
5352 }
5353
5354 const auto *actor = dynamic_cast<const heal_actor *>( use_fun->get_actor_ptr() );
5355
5356 return actor != nullptr &&
5357 actor->limb_power >= 0 &&
5358 actor->head_power >= 0 &&
5359 actor->torso_power >= 0;
5360 };
5361 item_location loc = game_menus::inv::titled_filter_menu( will_accept, u, _( "Use which item?" ) );
5362
5363 if( !loc ) {
5364 add_msg( _( "Never mind" ) );
5365 return false;
5366 }
5367 item &used = *loc;
5368 bool did_use = u.invoke_item( &used, heal_string, who.pos() );
5369 if( did_use ) {
5370 // Note: exiting a body part selection menu counts as use here
5371 u.mod_moves( -300 );
5372 }
5373 } else if( choice == sort_armor ) {
5374 show_armor_layers_ui( who );
5375 u.mod_moves( -100 );
5376 } else if( choice == attack ) {
5377 if( who.is_enemy() || query_yn( _( "You may be attacked! Proceed?" ) ) ) {
5378 u.melee_attack( who, true );
5379 who.on_attacked( u );
5380 }
5381 } else if( choice == disarm ) {
5382 if( who.is_enemy() || query_yn( _( "You may be attacked! Proceed?" ) ) ) {
5384 }
5385 } else if( choice == steal && query_yn( _( "You may be attacked! Proceed?" ) ) ) {
5387 }
5388
5389 return true;
5390}
hp_part body_window(const std::string &menu_header, bool show_all, bool precise, int normal_bonus, int head_bonus, int torso_bonus, float bleed, float bite, float infect, float bandage_power, float disinfectant_power) const
Displays menu with body part hp, optionally with hp estimation after healing.
Definition: character.cpp:5760
bool in_sleep_state() const override
Definition: character.cpp:9327
void melee_attack(Creature &t, bool allow_special, const matec_id *force_technique=nullptr, bool allow_unarmed=true)
Sets up a melee attack and handles melee attack function calls.
Definition: melee.cpp:445
int per_cur
Definition: character.h:267
bool prompt_dangerous_tile(const tripoint &dest_loc) const
Definition: game.cpp:8724
bool swap_critters(Creature &, Creature &)
Swaps positions of two creatures.
Definition: game.cpp:4778
float limb_power
How much hp to restore when healing limbs?
Definition: iuse_actor.h:1012
void talk_to_u(bool radio_contact=false)
Definition: npctalk.cpp:769
void on_attacked(const Creature &attacker)
Definition: npc.cpp:1445
void move_away_from(const tripoint &p, bool no_bash_atk=false, std::set< tripoint > *nomove=nullptr)
Definition: npcmove.cpp:2575
static const skill_id skill_firstaid("firstaid")
static void swap_pos(Creature &caster, const tripoint &target)
void try_disarm_npc(avatar &you, npc &target)
Try to disarm the NPC.
Definition: melee.cpp:2379
void try_steal_from_npc(avatar &you, npc &target)
Try to steal an item from the NPC's inventory.
Definition: melee.cpp:2456
item_location steal(avatar &you, player &victim)
Menu for stealing stuff.
item_location titled_filter_menu(item_filter filter, avatar &you, const std::string &title, const std::string &none_message="")
void push(monster &z)
Definition: monexamine.cpp:615

References _, add_msg(), uilist::addentry(), Character::body_window(), debug_mode, Character::disp_name(), Character::get_skill_level(), Character::in_sleep_state(), avatar::invoke_item(), Character::is_armed(), npc::is_enemy(), Character::is_mounted(), npc::is_player_ally(), heal_actor::limb_power, m_warning, Character::melee_attack(), Creature::mod_moves(), npc::move_away_from(), Character::name, npc::on_attacked(), Character::per_cur, Character::pos(), prompt_dangerous_tile(), monexamine::push(), uilist::query(), query_yn(), uilist::ret, show_armor_layers_ui(), skill_firstaid, game_menus::inv::steal(), string_format(), swap_critters(), swap_pos(), npc::talk_to_u(), uilist::text, game_menus::inv::titled_filter_menu(), avatar_funcs::try_disarm_npc(), avatar_funcs::try_steal_from_npc(), u, and avatar_action::use_item().

Referenced by examine().

◆ num_creatures()

size_t game::num_creatures ( ) const

Returns the approximate number of creatures in the reality bubble.

Because of performance restrictions it may return a slightly incorrect values (as it includes dead, but not yet cleaned up creatures).

Definition at line 4724 of file game.cpp.

4725{
4726 return critter_tracker->size() + active_npc.size() + 1; // 1 == g->u
4727}

References active_npc, and critter_tracker.

Referenced by display_visibility(), and fungal_effects::fungalize().

◆ on_move_effects()

void game::on_move_effects ( )

Definition at line 9757 of file game.cpp.

9758{
9759 // TODO: Move this to a character method
9760 if( !u.is_mounted() ) {
9761 const item muscle( "muscle" );
9762 for( const bionic_id &bid : u.get_bionic_fueled_with( muscle ) ) {
9763 if( u.has_active_bionic( bid ) ) {// active power gen
9764 u.mod_power_level( units::from_kilojoule( muscle.fuel_energy() ) * bid->fuel_efficiency );
9765 } else if( u.has_bionic( bid ) ) {// passive power gen
9766 u.mod_power_level( units::from_kilojoule( muscle.fuel_energy() ) * bid->passive_fuel_efficiency );
9767 }
9768 }
9769 const bionic_id bio_jointservo( "bio_jointservo" );
9771 if( u.movement_mode_is( CMM_RUN ) ) {
9773 } else {
9775 }
9776 }
9777 }
9778
9779 if( u.movement_mode_is( CMM_RUN ) ) {
9780 if( !u.can_run() ) {
9782 }
9783 }
9784
9785 // apply martial art move bonuses
9786 u.martial_arts_data->ma_onmove_effects( u );
9787
9789}
static const bionic_id bio_jointservo("bio_jointservo")
@ CMM_RUN
Definition: character.h:110
bool can_run()
source of truth of whether a Character can run
Definition: character.cpp:1270
bool movement_mode_is(character_movemode mode) const
Check against the character's current movement mode.
Definition: character.cpp:1560
std::vector< bionic_id > get_bionic_fueled_with(const item &it) const
Return bionic_id of bionics able to use it as fuel.
Definition: character.cpp:1866
bool has_bionic(const bionic_id &b) const
Returns true if the player has the entered bionic id.
Definition: character.cpp:1815
void do_ambient()
Definition: sounds.cpp:1615
constexpr quantity< value_type, energy_in_joule_tag > from_kilojoule(const value_type v)
Definition: units_energy.h:32
units::energy power_trigger
Power cost when the bionic's special effect is triggered.
Definition: bionics.h:43

References bio_jointservo, Character::can_run(), CMM_RUN, sfx::do_ambient(), units::from_kilojoule(), item::fuel_energy(), Character::get_bionic_fueled_with(), Character::has_active_bionic(), Character::has_bionic(), Character::is_mounted(), Character::martial_arts_data, Character::mod_power_level(), Character::movement_mode_is(), bionic_data::power_trigger, avatar::toggle_run_mode(), and u.

Referenced by phasing_move(), and walk_move().

◆ on_options_changed()

void game::on_options_changed ( )

Should be invoked whenever options change.

Definition at line 9791 of file game.cpp.

9792{
9793#if defined(TILES)
9794 tilecontext->on_options_changed();
9795#endif
9796 grid_tracker_ptr->on_options_changed();
9797}

References grid_tracker_ptr.

◆ open_consume_item_menu()

void game::open_consume_item_menu ( )
private

Definition at line 1503 of file handle_action.cpp.

1504{
1505 uilist as_m;
1506
1507 as_m.text = _( "What do you want to consume?" );
1508
1509 as_m.entries.emplace_back( 0, true, 'f', _( "Food" ) );
1510 as_m.entries.emplace_back( 1, true, 'd', _( "Drink" ) );
1511 as_m.entries.emplace_back( 2, true, 'm', _( "Medication" ) );
1512 as_m.query();
1513
1514 switch( as_m.ret ) {
1515 case 0:
1517 break;
1518 case 1:
1520 break;
1521 case 2:
1523 break;
1524 default:
1525 break;
1526 }
1527}
std::vector< uilist_entry > entries
Definition: ui.h:323
item_location consume_drink(player &p)
Consuming a drink item via a custom menu.
item_location consume_meds(player &p)
Consuming a medication item via a custom menu.
item_location consume_food(player &p)
Consuming a food item via a custom menu.

References _, game_menus::inv::consume_drink(), game_menus::inv::consume_food(), game_menus::inv::consume_meds(), avatar_action::eat(), uilist::entries, uilist::query(), uilist::ret, uilist::text, and u.

Referenced by handle_action().

◆ overmap_npc_move()

void game::overmap_npc_move ( )
private

Definition at line 4204 of file game.cpp.

4205{
4206 std::vector<npc *> travelling_npcs;
4207 static constexpr int move_search_radius = 600;
4208 for( auto &elem : overmap_buffer.get_npcs_near_player( move_search_radius ) ) {
4209 if( !elem ) {
4210 continue;
4211 }
4212 npc *npc_to_add = elem.get();
4213 if( ( !npc_to_add->is_active() || rl_dist( u.pos(), npc_to_add->pos() ) > SEEX * 2 ) &&
4214 npc_to_add->mission == NPC_MISSION_TRAVELLING ) {
4215 travelling_npcs.push_back( npc_to_add );
4216 }
4217 }
4218 for( auto &elem : travelling_npcs ) {
4219 if( elem->has_omt_destination() ) {
4220 if( !elem->omt_path.empty() && rl_dist( elem->omt_path.back(), elem->global_omt_location() ) > 2 ) {
4221 //recalculate path, we got distracted doing something else probably
4222 elem->omt_path.clear();
4223 }
4224 if( elem->omt_path.empty() ) {
4225 const tripoint_abs_omt &from = elem->global_omt_location();
4226 const tripoint_abs_omt &to = elem->goal;
4227 elem->omt_path = overmap_buffer.get_travel_path( elem->global_omt_location(), elem->goal,
4229 if( elem->omt_path.empty() ) {
4230 add_msg( m_debug, "%s couldn't find overmap path from %s to %s",
4231 elem->get_name(), from.to_string(), to.to_string() );
4232 elem->goal = npc::no_goal_point;
4233 elem->mission = NPC_MISSION_NULL;
4234 }
4235 } else {
4236 if( elem->omt_path.back() == elem->global_omt_location() ) {
4237 elem->omt_path.pop_back();
4238 }
4239 // TODO: fix point types
4240 elem->travel_overmap(
4241 project_to<coords::sm>( elem->omt_path.back() ).raw() );
4242 }
4243 reload_npcs();
4244 }
4245 }
4246 return;
4247}
std::vector< tripoint_abs_omt > omt_path
Route for overmap scale traveling.
Definition: character.h:1837
static constexpr tripoint_abs_omt no_goal_point
Definition: npc.h:1303
bool is_active() const
Definition: npc.cpp:2199
std::vector< tripoint_abs_omt > get_travel_path(const tripoint_abs_omt &src, const tripoint_abs_omt &dest, overmap_path_params params)
@ NPC_MISSION_NULL
Definition: npc.h:142
@ NPC_MISSION_TRAVELLING
Definition: npc.h:154
static overmap_path_params for_npc()

References add_msg(), overmap_path_params::for_npc(), overmapbuffer::get_npcs_near_player(), overmapbuffer::get_travel_path(), npc::is_active(), m_debug, npc::mission, npc::no_goal_point, NPC_MISSION_NULL, NPC_MISSION_TRAVELLING, Character::omt_path, overmap_buffer, Character::pos(), reload_npcs(), rl_dist(), SEEX, coords::coord_point< Point, Origin, Scale >::to_string(), and u.

Referenced by do_turn().

◆ peek() [1/2]

void game::peek ( )

Definition at line 5658 of file game.cpp.

5659{
5660 const std::optional<tripoint> p = choose_direction( _( "Peek where?" ), true );
5661 if( !p ) {
5662 return;
5663 }
5664
5665 if( p->z != 0 ) {
5666 const tripoint old_pos = u.pos();
5667 vertical_move( p->z, false, true );
5668
5669 if( old_pos != u.pos() ) {
5670 look_around();
5671 vertical_move( p->z * -1, false, true );
5672 }
5673 return;
5674 }
5675
5676 if( m.impassable( u.pos() + *p ) || m.obstructed_by_vehicle_rotation( u.pos(), u.pos() + *p ) ) {
5677 return;
5678 }
5679
5680 peek( u.pos() + *p );
5681}
std::optional< tripoint > choose_direction(const std::string &message, const bool allow_vertical)
Request player input of a direction, possibly including vertical component.
Definition: action.cpp:946

References _, choose_direction(), map::impassable(), look_around(), m, map::obstructed_by_vehicle_rotation(), peek(), Character::pos(), u, and vertical_move().

Referenced by handle_action(), and peek().

◆ peek() [2/2]

void game::peek ( const tripoint p)

Definition at line 5683 of file game.cpp.

5684{
5685 u.moves -= 200;
5686 tripoint prev = u.pos();
5687 u.setpos( p );
5688 tripoint center = p;
5689 const look_around_result result = look_around( /*show_window=*/true, center, center, false, false,
5690 true );
5691 u.setpos( prev );
5692
5693 if( result.peek_action && *result.peek_action == PA_BLIND_THROW ) {
5694 item_location loc;
5695 avatar_action::plthrow( u, loc, p );
5696 }
5698}

References center, map::invalidate_map_cache(), look_around(), m, Creature::moves, PA_BLIND_THROW, avatar_action::plthrow(), Character::pos(), Character::setpos(), u, and tripoint::z.

◆ perhaps_add_random_npc()

void game::perhaps_add_random_npc ( )
private

Definition at line 11099 of file game.cpp.

11100{
11101 static constexpr time_duration spawn_interval = 1_hours;
11102 if( !calendar::once_every( spawn_interval ) ) {
11103 return;
11104 }
11105 // Create a new NPC?
11106 // Only allow NPCs on 0 z-level, otherwise they can bug out due to lack of spots
11107 if( !get_option<bool>( "RANDOM_NPC" ) || ( !m.has_zlevels() && get_levz() != 0 ) ) {
11108 return;
11109 }
11110
11111 // We want the "NPC_DENSITY" to denote number of NPCs per week, per overmap, or so
11112 // But soft-cap it at about a standard year (4*14 days) worth
11113 const int npc_num = overmap_buffer.get_npcs_near_player(
11115 const double chance = npc_overmap::spawn_chance_in_hour( npc_num,
11116 get_option<float>( "NPC_DENSITY" ) );
11117 add_msg( m_debug, "Random NPC spawn chance %0.3f%%", chance * 100 );
11118 if( !x_in_y( chance, 1.0f ) ) {
11119 return;
11120 }
11121
11122 bool spawn_allowed = false;
11124 int counter = 0;
11125 while( !spawn_allowed ) {
11126 if( counter >= 100 ) {
11127 return;
11128 }
11129 // Shouldn't be larger than search radius or it might get swarmy at the edges
11130 static constexpr int radius_spawn_range = npc_overmap::density_search_radius;
11131 const tripoint_abs_omt u_omt = u.global_omt_location();
11132 spawn_point = u_omt + point( rng( -radius_spawn_range, radius_spawn_range ),
11133 rng( -radius_spawn_range, radius_spawn_range ) );
11134 spawn_point.z() = 0;
11135 const oter_id oter = overmap_buffer.ter( spawn_point );
11136 // Shouldn't spawn on lakes or rivers.
11137 // TODO: Prefer greater distance
11138 if( !is_river_or_lake( oter ) || rl_dist( u_omt.xy(), spawn_point.xy() ) < 30 ) {
11139 spawn_allowed = true;
11140 }
11141 counter += 1;
11142 }
11143 shared_ptr_fast<npc> tmp = make_shared_fast<npc>();
11144 tmp->randomize();
11145 std::string new_fac_id = "solo_";
11146 new_fac_id += tmp->name;
11147 // create a new "lone wolf" faction for this one NPC
11148 faction *new_solo_fac = faction_manager_ptr->add_new_faction( tmp->name, faction_id( new_fac_id ),
11149 faction_id( "no_faction" ) );
11150 tmp->set_fac( new_solo_fac ? new_solo_fac->id : faction_id( "no_faction" ) );
11151 // adds the npc to the correct overmap.
11152 // Only spawn random NPCs on z-level 0
11153 // TODO: fix point types
11154 tripoint submap_spawn = omt_to_sm_copy( spawn_point.raw() );
11155 tmp->spawn_at_sm( tripoint( submap_spawn.xy(), 0 ) );
11157 tmp->form_opinion( u );
11158 tmp->mission = NPC_MISSION_NULL;
11159 tmp->long_term_goal_action();
11160 tmp->add_new_mission( mission::reserve_random( ORIGIN_ANY_NPC, tmp->global_omt_location(),
11161 tmp->getID() ) );
11162 dbg( DL::Debug ) << "Spawning a random NPC at " << spawn_point;
11163 // This will make the new NPC active- if its nearby to the player
11164 load_npcs();
11165}
faction_id id
Definition: faction.h:83
point omt_to_sm_copy(point p)
@ Debug
Debug information (default: disabled).
@ ORIGIN_ANY_NPC
Definition: mission.h:46
double spawn_chance_in_hour(int current_npc_count, double density)
Chance that a random NPC spawns somewhere on overmap.
Definition: game.cpp:11088
static constexpr int density_search_radius
Radius of the area in which we count NPCs for random spawn chance.
Definition: npc.h:1423
bool is_river_or_lake(const oter_id &ter)
Definition: overmap.cpp:563

References add_msg(), dbg, Debug, npc_overmap::density_search_radius, faction_manager_ptr, get_levz(), overmapbuffer::get_npcs_near_player(), Character::global_omt_location(), map::has_zlevels(), faction_template::id, overmapbuffer::insert_npc(), is_river_or_lake(), load_npcs(), m, m_debug, NPC_MISSION_NULL, omt_to_sm_copy(), calendar::once_every(), ORIGIN_ANY_NPC, overmap_buffer, mission::reserve_random(), rl_dist(), rng(), npc_overmap::spawn_chance_in_hour(), overmapbuffer::ter(), u, x_in_y(), coords::coord_point< Point, Origin, Scale >::xy(), and tripoint::xy().

Referenced by do_turn().

◆ phasing_move()

bool game::phasing_move ( const tripoint dest,
bool  via_ramp = false 
)

Definition at line 9482 of file game.cpp.

9483{
9484 if( dest_loc.z != u.posz() && !via_ramp ) {
9485 // No vertical phasing yet
9486 return false;
9487 }
9488
9489 //probability travel through walls but not water
9490 tripoint dest = dest_loc;
9491 // tile is impassable
9492 int tunneldist = 0;
9493 const point d( sgn( dest.x - u.posx() ), sgn( dest.y - u.posy() ) );
9494 while( m.impassable( dest ) ||
9495 ( critter_at( dest ) != nullptr && tunneldist > 0 ) ) {
9496 //add 1 to tunnel distance for each impassable tile in the line
9497 tunneldist += 1;
9498 //Being dimensionally anchored prevents quantum shenanigans.
9499 if( u.worn_with_flag( "DIMENSIONAL_ANCHOR" ) || u.has_effect_with_flag( "DIMENSIONAL_ANCHOR" ) ) {
9501 _( "You try to quantum tunnel through the barrier, but something holds you back!" ) );
9502 return false;
9503 }
9504 if( tunneldist > 24 ) {
9505 add_msg( m_info, _( "It's too dangerous to tunnel that far!" ) );
9506 return false;
9507 }
9508
9509 dest.x += d.x;
9510 dest.y += d.y;
9511 }
9512
9514
9515 if( tunneldist != 0 ) {
9516 // -1 because power_cost for the first tile was already taken up by the bionic's activation
9517 if( ( tunneldist - 1 ) * power_cost > u.get_power_level() ) {
9518 // oops, not enough energy! Tunneling costs set amount of bionic power per impassable tile
9519 if( tunneldist * power_cost > u.get_max_power_level() ) {
9520 add_msg( _( "You try to quantum tunnel through the barrier but bounce off! You don't have enough bionic power capacity to travel that far." ) );
9521 } else {
9522 add_msg( _( "You try to quantum tunnel through the barrier but are reflected! You need %s of bionic power to travel that thickness of material." ),
9523 units::display( power_cost * tunneldist ) );
9524 }
9525 return false;
9526 }
9527
9528 if( u.in_vehicle ) {
9529 m.unboard_vehicle( u.pos() );
9530 }
9531
9532 add_msg( _( "You quantum tunnel through the %d-tile wide barrier!" ), tunneldist );
9533 //tunneling costs 100 bionic power per impassable tile, but the first 100 was already drained by activation.
9534 u.mod_power_level( -( ( tunneldist - 1 ) * power_cost ) );
9535 //tunneling costs 100 moves baseline, 50 per extra tile up to a cap of 500 moves
9536 u.moves -= ( 50 + ( tunneldist * 50 ) );
9537 u.setpos( dest );
9538
9539 if( m.veh_at( u.pos() ).part_with_feature( "BOARDABLE", true ) ) {
9540 m.board_vehicle( u.pos(), &u );
9541 }
9542
9543 u.grab( OBJECT_NONE );
9545 m.creature_on_trap( u );
9546 return true;
9547 }
9548
9549 return false;
9550}
bool worn_with_flag(const std::string &flag, const bodypart_id &bp=bodypart_str_id::NULL_ID()) const
Returns true if the player is wearing an item with the given flag.
Definition: character.cpp:3265
units::energy get_max_power_level() const
Definition: character.cpp:1910
bool has_effect_with_flag(const std::string &flag, body_part bp=num_bp) const
Check if creature has any effect with the given flag.
Definition: creature.cpp:1229
void on_move_effects()
Definition: game.cpp:9757
void board_vehicle(const tripoint &p, player *pl)
Definition: map.cpp:1114
constexpr int sgn(const T x)
Definition: enums.h:8
static const bionic_id bio_probability_travel("bio_probability_travel")
std::string display(const units::energy v)
Definition: units.cpp:59
units::energy power_activate
Power cost on activation.
Definition: bionics.h:37

References _, add_msg(), player::add_msg_if_player(), bio_probability_travel, map::board_vehicle(), map::creature_on_trap(), critter_at(), anonymous_namespace{iexamine_elevator.cpp}::elevator::dest(), units::display(), Character::get_max_power_level(), Character::get_power_level(), avatar::grab(), Creature::has_effect_with_flag(), map::impassable(), Character::in_vehicle, m, m_info, Character::mod_power_level(), Creature::moves, OBJECT_NONE, on_move_effects(), Character::pos(), Character::posx(), Character::posy(), Character::posz(), bionic_data::power_activate, Character::setpos(), sgn(), u, map::unboard_vehicle(), map::veh_at(), Character::worn_with_flag(), point::x, point::y, and tripoint::z.

◆ pickup() [1/2]

void game::pickup ( )
private

Definition at line 5629 of file game.cpp.

5630{
5631 const std::optional<tripoint> examp_ = choose_adjacent_highlight( _( "Pickup where?" ),
5632 _( "There is nothing to pick up nearby." ),
5633 ACTION_PICKUP, false );
5634 if( !examp_ ) {
5635 return;
5636 }
5637 pickup( *examp_ );
5638}

References _, ACTION_PICKUP, choose_adjacent_highlight(), and pickup().

Referenced by handle_action(), and pickup().

◆ pickup() [2/2]

void game::pickup ( const tripoint p)
private

Definition at line 5640 of file game.cpp.

5641{
5642 // Highlight target
5643 shared_ptr_fast<game::draw_callback_t> hilite_cb = make_shared_fast<game::draw_callback_t>( [&]() {
5644 m.drawsq( w_terrain, p, drawsq_params().highlight( true ) );
5645 } );
5646 add_draw_callback( hilite_cb );
5647
5648 pickup::pick_up( p, 0 );
5649}

References add_draw_callback(), map::drawsq(), m, pickup::pick_up(), and w_terrain.

◆ pickup_feet()

void game::pickup_feet ( )
private

Definition at line 5651 of file game.cpp.

5652{
5653 pickup::pick_up( u.pos(), 1 );
5654}

References pickup::pick_up(), Character::pos(), and u.

Referenced by handle_action().

◆ place_critter_around() [1/2]

monster * game::place_critter_around ( const mtype_id id,
const tripoint center,
int  radius 
)

Definition at line 4672 of file game.cpp.

4673{
4674 // TODO: change this into an assert, it must never happen.
4675 if( id.is_null() ) {
4676 return nullptr;
4677 }
4678 return place_critter_around( make_shared_fast<monster>( id ), center, radius );
4679}
monster * place_critter_around(const mtype_id &id, const tripoint &center, int radius)
Definition: game.cpp:4672

References center, and place_critter_around().

Referenced by place_critter_around(), place_critter_at(), replace_stair_monsters(), and start_game().

◆ place_critter_around() [2/2]

monster * game::place_critter_around ( const shared_ptr_fast< monster > &  mon,
const tripoint center,
int  radius,
bool  forced = false 
)

Definition at line 4681 of file game.cpp.

4685{
4686 std::optional<tripoint> where;
4687 if( forced || can_place_monster( *mon, center ) ) {
4688 where = center;
4689 }
4690
4691 // This loop ensures the monster is placed as close to the center as possible,
4692 // but all places that equally far from the center have the same probability.
4693 for( int r = 1; r <= radius && !where; ++r ) {
4695 }
4696
4697 if( !where ) {
4698 return nullptr;
4699 }
4700 mon->spawn( *where );
4701 return critter_tracker->add( mon ) ? mon.get() : nullptr;
4702}
static std::optional< tripoint > choose_where_to_place_monster(const monster &mon, const tripoint_range< tripoint > &range)
Definition: game.cpp:4654
static bool can_place_monster(const monster &mon, const tripoint &p)
Definition: game.cpp:4638

References can_place_monster(), center, choose_where_to_place_monster(), critter_tracker, m, and map::points_in_radius().

◆ place_critter_at() [1/2]

monster * game::place_critter_at ( const mtype_id id,
const tripoint p 
)

Adds critters to the reality bubble, creating them if necessary.

Functions taking a id parameter will construct a monster based on that id, (with default properties). Functions taking a mon parameter will use the supplied monster instance instead (which must not be null). Note: the monster will not be upgraded by these functions, it is placed as is.

place_critter_at will place the creature exactly at the given point.

place_critter_around will place the creature around the center p within the given radius (radius 0 means only the center point is used). The chosen point will be as close to the center as possible.

place_critter_within will place the creature at a random point within that given range. (All points within have equal probability.)

Returns
All functions return null if the creature could not be placed (usually because the target is not suitable for it: may be a solid wall, or air, or already occupied by some creature). If the creature has been placed, it returns a pointer to it (which is the same as the one contained in mon).

Definition at line 4662 of file game.cpp.

4663{
4664 return place_critter_around( id, p, 0 );
4665}

References place_critter_around().

Referenced by fungal_effects::fungalize(), revive_corpse(), fungal_effects::spread_fungus_one_tile(), and update_stair_monsters().

◆ place_critter_at() [2/2]

monster * game::place_critter_at ( const shared_ptr_fast< monster > &  mon,
const tripoint p 
)

Definition at line 4667 of file game.cpp.

4668{
4669 return place_critter_around( mon, p, 0 );
4670}

References place_critter_around().

◆ place_critter_within() [1/2]

monster * game::place_critter_within ( const mtype_id id,
const tripoint_range< tripoint > &  range 
)

Definition at line 4704 of file game.cpp.

4705{
4706 // TODO: change this into an assert, it must never happen.
4707 if( id.is_null() ) {
4708 return nullptr;
4709 }
4710 return place_critter_within( make_shared_fast<monster>( id ), range );
4711}
monster * place_critter_within(const mtype_id &id, const tripoint_range< tripoint > &range)
Definition: game.cpp:4704

References place_critter_within(), and range.

Referenced by place_critter_within().

◆ place_critter_within() [2/2]

monster * game::place_critter_within ( const shared_ptr_fast< monster > &  mon,
const tripoint_range< tripoint > &  range 
)

Definition at line 4713 of file game.cpp.

4715{
4716 const std::optional<tripoint> where = choose_where_to_place_monster( *mon, range );
4717 if( !where ) {
4718 return nullptr;
4719 }
4720 mon->spawn( *where );
4721 return critter_tracker->add( mon ) ? mon.get() : nullptr;
4722}

References choose_where_to_place_monster(), critter_tracker, and range.

◆ place_player()

point game::place_player ( const tripoint dest)
Dexterity increases chance of avoiding cuts on sharp terrain

Definition at line 9120 of file game.cpp.

9121{
9122 const optional_vpart_position vp1 = m.veh_at( dest_loc );
9123 if( const std::optional<std::string> label = vp1.get_label() ) {
9124 add_msg( m_info, _( "Label here: %s" ), *label );
9125 }
9126 std::string signage = m.get_signage( dest_loc );
9127 if( !signage.empty() ) {
9128 if( !u.has_trait( trait_ILLITERATE ) ) {
9129 add_msg( m_info, _( "The sign says: %s" ), signage );
9130 } else {
9131 add_msg( m_info, _( "There is a sign here, but you are unable to read it." ) );
9132 }
9133 }
9134 if( m.has_graffiti_at( dest_loc ) ) {
9135 if( !u.has_trait( trait_ILLITERATE ) ) {
9136 add_msg( m_info, _( "Written here: %s" ), m.graffiti_at( dest_loc ) );
9137 } else {
9138 add_msg( m_info, _( "Something is written here, but you are unable to read it." ) );
9139 }
9140 }
9141 // TODO: Move the stuff below to a Character method so that NPCs can reuse it
9142 if( m.has_flag( "ROUGH", dest_loc ) && ( !u.in_vehicle ) && ( !u.is_mounted() ) ) {
9143 if( one_in( 5 ) && u.get_armor_bash( bodypart_id( "foot_l" ) ) < rng( 2, 5 ) ) {
9144 add_msg( m_bad, _( "You hurt your left foot on the %s!" ),
9145 m.has_flag_ter( "ROUGH", dest_loc ) ? m.tername( dest_loc ) : m.furnname(
9146 dest_loc ) );
9147 u.deal_damage( nullptr, bodypart_id( "foot_l" ), damage_instance( DT_CUT, 1 ) );
9148 }
9149 if( one_in( 5 ) && u.get_armor_bash( bodypart_id( "foot_r" ) ) < rng( 2, 5 ) ) {
9150 add_msg( m_bad, _( "You hurt your right foot on the %s!" ),
9151 m.has_flag_ter( "ROUGH", dest_loc ) ? m.tername( dest_loc ) : m.furnname(
9152 dest_loc ) );
9153 u.deal_damage( nullptr, bodypart_id( "foot_l" ), damage_instance( DT_CUT, 1 ) );
9154 }
9155 }
9156 ///\EFFECT_DEX increases chance of avoiding cuts on sharp terrain
9157 if( m.has_flag( "SHARP", dest_loc ) && !one_in( 3 ) && !x_in_y( 1 + u.dex_cur / 2.0, 40 ) &&
9158 ( !u.in_vehicle && !m.veh_at( dest_loc ) ) && ( !u.has_trait( trait_PARKOUR ) ||
9159 one_in( 4 ) ) && ( u.has_trait( trait_THICKSKIN ) ? !one_in( 8 ) : true ) ) {
9160 if( u.is_mounted() ) {
9161 add_msg( _( "Your %s gets cut!" ), u.mounted_creature->get_name() );
9162 u.mounted_creature->apply_damage( nullptr, bodypart_id( "torso" ), rng( 1, 10 ) );
9163 } else {
9164 const bodypart_id bp = u.get_random_body_part();
9165 if( u.deal_damage( nullptr, bp, damage_instance( DT_CUT, rng( 1, 10 ) ) ).total_damage() > 0 ) {
9166 //~ 1$s - bodypart name in accusative, 2$s is terrain name.
9167 add_msg( m_bad, _( "You cut your %1$s on the %2$s!" ),
9168 body_part_name_accusative( bp->token ),
9169 m.has_flag_ter( "SHARP", dest_loc ) ? m.tername( dest_loc ) : m.furnname(
9170 dest_loc ) );
9171 }
9172 }
9173 }
9174 if( m.has_flag( "UNSTABLE", dest_loc ) && !u.is_mounted() ) {
9175 u.add_effect( effect_bouldering, 1_turns, num_bp );
9176 } else if( u.has_effect( effect_bouldering ) ) {
9178 }
9179 if( m.has_flag_ter_or_furn( TFLAG_NO_SIGHT, dest_loc ) ) {
9180 u.add_effect( effect_no_sight, 1_turns, num_bp );
9181 } else if( u.has_effect( effect_no_sight ) ) {
9183 }
9184
9185 // If we moved out of the nonant, we need update our map data
9186 if( m.has_flag( "SWIMMABLE", dest_loc ) && u.has_effect( effect_onfire ) ) {
9187 add_msg( _( "The water puts out the flames!" ) );
9189 if( u.is_mounted() ) {
9190 monster *mon = u.mounted_creature.get();
9191 if( mon->has_effect( effect_onfire ) ) {
9193 }
9194 }
9195 }
9196
9197 if( monster *const mon_ptr = critter_at<monster>( dest_loc ) ) {
9198 // We displaced a monster. It's probably a bug if it wasn't a friendly mon...
9199 // Immobile monsters can't be displaced.
9200 monster &critter = *mon_ptr;
9201 // TODO: handling for ridden creatures other than players mount.
9202 if( !critter.has_effect( effect_ridden ) ) {
9203 if( u.is_mounted() ) {
9204 std::vector<tripoint> valid;
9205 for( const tripoint &jk : m.points_in_radius( critter.pos(), 1 ) ) {
9206 if( is_empty( jk ) ) {
9207 valid.push_back( jk );
9208 }
9209 }
9210 if( !valid.empty() ) {
9211 critter.move_to( random_entry( valid ) );
9212 add_msg( _( "You push the %s out of the way." ), critter.name() );
9213 } else {
9214 add_msg( _( "There is no room to push the %s out of the way." ), critter.name() );
9215 return u.pos().xy();
9216 }
9217 } else {
9218 critter.move_to( u.pos(), false,
9219 true ); // Force the movement even though the player is there right now.
9220 add_msg( _( "You displace the %s." ), critter.name() );
9221 }
9222 } else if( !u.has_effect( effect_riding ) ) {
9223 add_msg( _( "You cannot move the %s out of the way." ), critter.name() );
9224 return u.pos().xy();
9225 }
9226 }
9227
9228 // If the player is in a vehicle, unboard them from the current part
9229 if( u.in_vehicle ) {
9230 m.unboard_vehicle( u.pos() );
9231 }
9232 // Move the player
9233 // Start with z-level, to make it less likely that old functions (2D ones) freak out
9234 if( m.has_zlevels() && dest_loc.z != get_levz() ) {
9235 vertical_shift( dest_loc.z );
9236 }
9237
9238 if( u.is_hauling() && ( !m.can_put_items( dest_loc ) ||
9239 m.has_flag( TFLAG_DEEP_WATER, dest_loc ) ||
9240 vp1 ) ) {
9241 u.stop_hauling();
9242 }
9243 u.setpos( dest_loc );
9244 if( u.is_mounted() ) {
9245 monster *mon = u.mounted_creature.get();
9246 mon->setpos( dest_loc );
9247 mon->process_triggers();
9248 m.creature_in_field( *mon );
9249 }
9250 point submap_shift = update_map( u );
9251 // Important: don't use dest_loc after this line. `update_map` may have shifted the map
9252 // and dest_loc was not adjusted and therefore is still in the un-shifted system and probably wrong.
9253 // If you must use it you can calculate the position in the new, shifted system with
9254 // adjusted_pos = ( old_pos.x - submap_shift.x * SEEX, old_pos.y - submap_shift.y * SEEY, old_pos.z )
9255
9256 //Auto pulp or butcher and Auto foraging
9257 if( get_option<bool>( "AUTO_FEATURES" ) && mostseen == 0 && !u.is_mounted() ) {
9259
9260 const std::string forage_type = get_option<std::string>( "AUTO_FORAGING" );
9261 if( forage_type != "off" ) {
9262 const auto forage = [&]( const tripoint & pos ) {
9263 const auto &xter_t = m.ter( pos ).obj().examine;
9264 const auto &xfurn_t = m.furn( pos ).obj().examine;
9265 const bool forage_everything = forage_type == "both";
9266 const bool forage_bushes = forage_everything || forage_type == "bushes";
9267 const bool forage_trees = forage_everything || forage_type == "trees";
9268 if( xter_t == &iexamine::none && xfurn_t == &iexamine::none ) {
9269 return;
9270 } else if( ( forage_bushes && xter_t == &iexamine::shrub_marloss ) ||
9271 ( forage_bushes && xter_t == &iexamine::shrub_wildveggies ) ||
9272 ( forage_bushes && xter_t == &iexamine::harvest_ter_nectar ) ||
9273 ( forage_trees && xter_t == &iexamine::tree_marloss ) ||
9274 ( forage_trees && xter_t == &iexamine::harvest_ter ) ||
9275 ( forage_trees && xter_t == &iexamine::harvest_ter_nectar )
9276 ) {
9277 xter_t( u, pos );
9278 } else if( ( forage_everything && xfurn_t == &iexamine::harvest_furn ) ||
9279 ( forage_everything && xfurn_t == &iexamine::harvest_furn_nectar )
9280 ) {
9281 xfurn_t( u, pos );
9282 }
9283 };
9284
9285 for( auto &elem : adjacentDir ) {
9286 forage( u.pos() + direction_XY( elem ) );
9287 }
9288 }
9289
9290 const std::string pulp_butcher = get_option<std::string>( "AUTO_PULP_BUTCHER" );
9291 if( pulp_butcher == "butcher" && u.max_quality( quality_id( "BUTCHER" ) ) > INT_MIN ) {
9292 std::vector<item *> corpses;
9293
9294 for( item &it : m.i_at( u.pos() ) ) {
9295 corpses.push_back( &it );
9296 }
9297
9298 if( !corpses.empty() ) {
9299 u.assign_activity( activity_id( "ACT_BUTCHER" ), 0, true );
9300 for( item *it : corpses ) {
9301 u.activity.targets.emplace_back( map_cursor( u.pos() ), it );
9302 }
9303 }
9304 } else if( pulp_butcher == "pulp" || pulp_butcher == "pulp_adjacent" ) {
9305 const auto pulp = [&]( const tripoint & pos ) {
9306 for( const auto &maybe_corpse : m.i_at( pos ) ) {
9307 if( maybe_corpse.is_corpse() && maybe_corpse.can_revive() &&
9308 !maybe_corpse.get_mtype()->bloodType().obj().has_acid ) {
9310 u.activity.placement = m.getabs( pos );
9311 u.activity.auto_resume = true;
9312 u.activity.str_values.push_back( "auto_pulp_no_acid" );
9313 return;
9314 }
9315 }
9316 };
9317
9318 if( pulp_butcher == "pulp_adjacent" ) {
9319 for( auto &elem : adjacentDir ) {
9320 pulp( u.pos() + direction_XY( elem ) );
9321 }
9322 } else {
9323 pulp( u.pos() );
9324 }
9325 }
9326 }
9327
9328 //Autopickup
9329 if( !u.is_mounted() && get_option<bool>( "AUTO_PICKUP" ) && !u.is_hauling() &&
9330 ( !get_option<bool>( "AUTO_PICKUP_SAFEMODE" ) || mostseen == 0 ) &&
9331 ( m.has_items( u.pos() ) || get_option<bool>( "AUTO_PICKUP_ADJACENT" ) ) ) {
9332 pickup::pick_up( u.pos(), -1 );
9333 }
9334
9335 // If the new tile is a boardable part, board it
9336 if( vp1.part_with_feature( "BOARDABLE", true ) && !u.is_mounted() ) {
9337 m.board_vehicle( u.pos(), &u );
9338 }
9339
9340 // Traps!
9341 // Try to detect.
9343 if( u.is_mounted() ) {
9345 } else {
9346 m.creature_on_trap( u );
9347 }
9348 // Drench the player if swimmable
9349 if( m.has_flag( "SWIMMABLE", u.pos() ) &&
9350 !( u.is_mounted() || ( u.in_vehicle && vp1->vehicle().can_float() ) ) ) {
9351 u.drench( 40, { { bp_foot_l, bp_foot_r, bp_leg_l, bp_leg_r } }, false );
9352 }
9353
9354 // List items here
9355 if( !m.has_flag( "SEALED", u.pos() ) ) {
9356 if( get_option<bool>( "NO_AUTO_PICKUP_ZONES_LIST_ITEMS" ) ||
9357 !check_zone( zone_type_id( "NO_AUTO_PICKUP" ), u.pos() ) ) {
9358 if( u.is_blind() && !m.i_at( u.pos() ).empty() ) {
9359 add_msg( _( "There's something here, but you can't see what it is." ) );
9360 } else if( m.has_items( u.pos() ) ) {
9361 std::vector<std::string> names;
9362 std::vector<size_t> counts;
9363 std::vector<item> items;
9364 for( auto &tmpitem : m.i_at( u.pos() ) ) {
9365
9366 std::string next_tname = tmpitem.tname();
9367 std::string next_dname = tmpitem.display_name();
9368 bool by_charges = tmpitem.count_by_charges();
9369 bool got_it = false;
9370 for( size_t i = 0; i < names.size(); ++i ) {
9371 if( by_charges && next_tname == names[i] ) {
9372 counts[i] += tmpitem.charges;
9373 got_it = true;
9374 break;
9375 } else if( next_dname == names[i] ) {
9376 counts[i] += 1;
9377 got_it = true;
9378 break;
9379 }
9380 }
9381 if( !got_it ) {
9382 if( by_charges ) {
9383 names.push_back( tmpitem.tname( tmpitem.charges ) );
9384 counts.push_back( tmpitem.charges );
9385 } else {
9386 names.push_back( tmpitem.display_name( 1 ) );
9387 counts.push_back( 1 );
9388 }
9389 items.push_back( tmpitem );
9390 }
9391 if( names.size() > 10 ) {
9392 break;
9393 }
9394 }
9395 for( size_t i = 0; i < names.size(); ++i ) {
9396 if( !items[i].count_by_charges() ) {
9397 names[i] = items[i].display_name( counts[i] );
9398 } else {
9399 names[i] = items[i].tname( counts[i] );
9400 }
9401 }
9402 int and_the_rest = 0;
9403 for( size_t i = 0; i < names.size(); ++i ) {
9404 //~ number of items: "<number> <item>"
9405 std::string fmt = vgettext( "%1$d %2$s", "%1$d %2$s", counts[i] );
9406 names[i] = string_format( fmt, counts[i], names[i] );
9407 // Skip the first two.
9408 if( i > 1 ) {
9409 and_the_rest += counts[i];
9410 }
9411 }
9412 if( names.size() == 1 ) {
9413 add_msg( _( "You see here %s." ), names[0] );
9414 } else if( names.size() == 2 ) {
9415 add_msg( _( "You see here %s and %s." ), names[0], names[1] );
9416 } else if( names.size() == 3 ) {
9417 add_msg( _( "You see here %s, %s, and %s." ), names[0], names[1], names[2] );
9418 } else if( and_the_rest < 7 ) {
9419 add_msg( vgettext( "You see here %s, %s and %d more item.",
9420 "You see here %s, %s and %d more items.",
9421 and_the_rest ),
9422 names[0], names[1], and_the_rest );
9423 } else {
9424 add_msg( _( "You see here %s and many more items." ), names[0] );
9425 }
9426 }
9427 }
9428 }
9429
9430 if( ( vp1.part_with_feature( "CONTROL_ANIMAL", true ) ||
9431 vp1.part_with_feature( "CONTROLS", true ) ) && u.in_vehicle && !u.is_mounted() ) {
9432 add_msg( _( "There are vehicle controls here." ) );
9433 if( !u.has_trait( trait_id( "WAYFARER" ) ) ) {
9434 add_msg( m_info, _( "%s to drive." ), press_x( ACTION_CONTROL_VEHICLE ) );
9435 }
9436 } else if( vp1.part_with_feature( "CONTROLS", true ) && u.in_vehicle &&
9437 u.is_mounted() ) {
9438 add_msg( _( "There are vehicle controls here but you cannot reach them whilst mounted." ) );
9439 }
9440 return submap_shift;
9441}
std::string body_part_name_accusative(body_part bp, int number)
Returns the matching accusative name of the body_part token, i.e.
Definition: bodypart.cpp:331
void drench(int saturation, const body_part_set &flags, bool ignore_waterproof)
Drenches the player with water, saturation is the percent gotten wet.
Definition: suffer.cpp:1709
bool is_hauling() const
Definition: character.cpp:9191
void stop_hauling()
Definition: character.cpp:9182
bodypart_id get_random_body_part(bool main=false) const
Definition: creature.cpp:1667
void vertical_shift(int z_after)
Actual z-level movement part of vertical_move.
Definition: game.cpp:10611
bool check_zone(const zone_type_id &type, const tripoint &where) const
Definition: game.cpp:6044
std::string furnname(const tripoint &p)
Definition: map.cpp:1534
bool has_flag_ter_or_furn(const std::string &flag, const tripoint &p) const
Definition: map.cpp:2404
bool has_graffiti_at(const tripoint &p) const
Definition: map.cpp:7980
bool has_items(const tripoint &p) const
Checks for existence of items.
Definition: map.cpp:4891
const std::string & graffiti_at(const tripoint &p) const
Definition: map.cpp:7969
bool has_flag_ter(const std::string &flag, const tripoint &p) const
Definition: map.cpp:2394
bool can_put_items(const tripoint &p) const
Definition: map.cpp:2380
void setpos(const tripoint &p) override
Definition: monster.cpp:234
bool move_to(const tripoint &p, bool force=false, bool step_on_critter=false, float stagger_adjustment=1.0)
Attempt to move to p.
Definition: monmove.cpp:1561
void process_triggers()
Definition: monster.cpp:1238
std::optional< std::string > get_label() const
std::vector< std::string > str_values
bool auto_resume
If true, the activity will be auto-resumed next time the player attempts an identical activity.
static const efftype_id effect_riding("riding")
static const trait_id trait_ILLITERATE("ILLITERATE")
static const efftype_id effect_bouldering("bouldering")
static const trait_id trait_PARKOUR("PARKOUR")
static const efftype_id effect_no_sight("no_sight")
static const trait_id trait_THICKSKIN("THICKSKIN")
static const efftype_id effect_onfire("onfire")
point direction_XY(const direction dir)
Definition: line.cpp:433
@ TFLAG_NO_SIGHT
Definition: mapdata.h:284
@ TFLAG_DEEP_WATER
Definition: mapdata.h:302
static std::map< nameFlags, std::vector< std::string > > names
Definition: name.cpp:18
const int INDEFINITELY_LONG
A number that represents the longest possible action.
void search_surroundings(Character &who)
Search surrounding squares for traps (and maybe other things in the future).
void shrub_wildveggies(player &p, const tripoint &examp)
Definition: iexamine.cpp:3598
void shrub_marloss(player &p, const tripoint &examp)
Definition: iexamine.cpp:3563
void harvest_ter(player &p, const tripoint &examp)
Definition: iexamine.cpp:2035
void harvest_furn(player &p, const tripoint &examp)
Definition: iexamine.cpp:2014
void harvest_ter_nectar(player &p, const tripoint &examp)
Definition: iexamine.cpp:2023
void harvest_furn_nectar(player &p, const tripoint &examp)
Definition: iexamine.cpp:2005
void tree_marloss(player &p, const tripoint &examp)
Definition: iexamine.cpp:3577
string_id< zone_type > zone_type_id
Definition: type_id.h:202

References _, ACTION_CONTROL_VEHICLE, Character::activity, Creature::add_effect(), add_msg(), Character::assign_activity(), player_activity::auto_resume, map::board_vehicle(), body_part_name_accusative(), bp_foot_l, bp_foot_r, bp_leg_l, bp_leg_r, map::can_put_items(), check_zone(), map::creature_in_field(), map::creature_on_trap(), Character::deal_damage(), Character::dex_cur, direction_XY(), Character::drench(), DT_CUT, EAST, effect_bouldering, effect_no_sight, effect_onfire, effect_ridden, effect_riding, item_stack::empty(), map_data_common_t::examine, map::furn(), map::furnname(), Character::get_armor_bash(), optional_vpart_position::get_label(), get_levz(), Creature::get_random_body_part(), map::get_signage(), map::getabs(), map::graffiti_at(), iexamine::harvest_furn(), iexamine::harvest_furn_nectar(), iexamine::harvest_ter(), iexamine::harvest_ter_nectar(), Creature::has_effect(), map::has_flag(), map::has_flag_ter(), map::has_flag_ter_or_furn(), map::has_graffiti_at(), map::has_items(), Character::has_trait(), map::has_zlevels(), map::i_at(), Character::in_vehicle, calendar::INDEFINITELY_LONG, Character::is_blind(), is_empty(), Character::is_hauling(), Character::is_mounted(), m, m_bad, m_info, visitable< T >::max_quality(), mostseen, Character::mounted_creature, monster::move_to(), monster::name(), Name::names, iexamine::none(), NORTH, NORTHEAST, NORTHWEST, num_bp, int_id< T >::obj(), one_in(), optional_vpart_position::part_with_feature(), pickup::pick_up(), player_activity::placement, map::points_in_radius(), Character::pos(), monster::pos(), press_x(), monster::process_triggers(), random_entry(), Creature::remove_effect(), rng(), character_funcs::search_surroundings(), Character::setpos(), monster::setpos(), iexamine::shrub_marloss(), iexamine::shrub_wildveggies(), SOUTH, SOUTHEAST, SOUTHWEST, Character::stop_hauling(), player_activity::str_values, string_format(), player_activity::targets, map::ter(), map::tername(), TFLAG_DEEP_WATER, TFLAG_NO_SIGHT, trait_ILLITERATE, trait_PARKOUR, trait_THICKSKIN, iexamine::tree_marloss(), u, map::unboard_vehicle(), update_map(), map::veh_at(), vertical_shift(), vgettext(), WEST, x_in_y(), tripoint::xy(), and tripoint::z.

Referenced by place_player_overmap(), and walk_move().

◆ place_player_overmap()

void game::place_player_overmap ( const tripoint_abs_omt om_dest)

Definition at line 9443 of file game.cpp.

9444{
9445 // if player is teleporting around, they don't bring their horse with them
9446 if( u.is_mounted() ) {
9448 u.mounted_creature->remove_effect( effect_ridden );
9449 u.mounted_creature = nullptr;
9450 }
9451 // offload the active npcs.
9452 unload_npcs();
9453 for( monster &critter : all_monsters() ) {
9454 despawn_monster( critter );
9455 }
9456 if( u.in_vehicle ) {
9457 m.unboard_vehicle( u.pos() );
9458 }
9459
9461 const int minz = m.has_zlevels() ? -OVERMAP_DEPTH : get_levz();
9462 const int maxz = m.has_zlevels() ? OVERMAP_HEIGHT : get_levz();
9463 for( int z = minz; z <= maxz; z++ ) {
9464 m.clear_vehicle_list( z );
9465 }
9467 // offset because load_map expects the coordinates of the top left corner, but the
9468 // player will be centered in the middle of the map.
9469 // TODO: fix point types
9470 const tripoint map_sm_pos(
9471 project_to<coords::sm>( om_dest ).raw() + point( -HALF_MAPSIZE, -HALF_MAPSIZE ) );
9472 const tripoint player_pos( u.pos().xy(), map_sm_pos.z );
9473 load_map( map_sm_pos );
9474 load_npcs();
9475 m.spawn_monsters( true ); // Static monsters
9477 // update weather now as it could be different on the new location
9479 place_player( player_pos );
9480}
point place_player(const tripoint &dest)
Definition: game.cpp:9120
void unload_npcs()
Unloads all NPCs.
Definition: game.cpp:870
void update_overmap_seen()
Definition: game.cpp:10789
level_cache & access_cache(int zlev)
Definition: map.cpp:8890
void clear_vehicle_list(int zlev)
Definition: map.cpp:391
void clear_vehicle_cache()
Definition: map.cpp:373
std::bitset< MAPSIZE_X *MAPSIZE_Y > map_memory_seen_cache
Definition: map.h:351

References map::access_cache(), all_monsters(), map::clear_vehicle_cache(), map::clear_vehicle_list(), despawn_monster(), effect_ridden, effect_riding, get_levz(), get_weather, HALF_MAPSIZE, map::has_zlevels(), Character::in_vehicle, Character::is_mounted(), load_map(), load_npcs(), m, level_cache::map_memory_seen_cache, Character::mounted_creature, weather_manager::nextweather, OVERMAP_DEPTH, OVERMAP_HEIGHT, place_player(), Character::pos(), Creature::remove_effect(), map::spawn_monsters(), calendar::turn, u, map::unboard_vehicle(), unload_npcs(), update_overmap_seen(), tripoint::xy(), and tripoint::z.

◆ place_vehicle_nearby()

vehicle * game::place_vehicle_nearby ( const vproto_id id,
const point_abs_omt origin,
int  min_distance,
int  max_distance,
const std::vector< std::string > &  omt_search_types = {} 
)
private

Definition at line 766 of file game.cpp.

769{
770 std::vector<std::string> search_types = omt_search_types;
771 if( search_types.empty() ) {
772 vehicle veh( id );
773 if( veh.can_float() ) {
774 search_types.push_back( "river" );
775 search_types.push_back( "lake" );
776 } else {
777 search_types.push_back( "field" );
778 search_types.push_back( "road" );
779 }
780 }
781 for( const std::string &search_type : search_types ) {
782 omt_find_params find_params;
783 find_params.must_see = false;
784 find_params.cant_see = false;
785 find_params.types.emplace_back( search_type, ot_match_type::type );
786 // find nearest road
787 find_params.min_distance = min_distance;
788 find_params.search_range = max_distance;
789 // if player spawns underground, park their car on the surface.
790 const tripoint_abs_omt omt_origin( origin, 0 );
791 for( const tripoint_abs_omt &goal : overmap_buffer.find_all( omt_origin, find_params ) ) {
792 // try place vehicle there.
793 tinymap target_map;
794 target_map.load( project_to<coords::sm>( goal ), false );
795 const tripoint tinymap_center( SEEX, SEEY, goal.z() );
796 static constexpr std::array<units::angle, 4> angles = {{
797 0_degrees, 90_degrees, 180_degrees, 270_degrees
798 }
799 };
800 vehicle *veh = target_map.add_vehicle(
801 id, tinymap_center, random_entry( angles ), rng( 50, 80 ), 0, false );
802 if( veh ) {
803 tripoint abs_local = m.getlocal( target_map.getabs( tinymap_center ) );
804 veh->sm_pos = ms_to_sm_remain( abs_local );
805 veh->pos = abs_local.xy();
807 veh->tracking_on = true;
808 target_map.save();
809 return veh;
810 }
811 }
812 }
813 return nullptr;
814}
void save()
Add currently loaded submaps (in grid) to the mapbuffer.
Definition: map.cpp:6735
vehicle * add_vehicle(const vgroup_id &type, const tripoint &p, units::angle dir, int init_veh_fuel=-1, int init_veh_status=-1, bool merge_wrecks=true)
Definition: mapgen.cpp:5438
void add_vehicle(vehicle *veh)
Add the vehicle to be tracked in the overmap.
std::vector< tripoint_abs_omt > find_all(const tripoint_abs_omt &origin, const omt_find_params &params)
Find all places with the specific overmap terrain type.
Definition: map.h:2065
point pos
Position of the vehicle inside the submap that contains the vehicle.
Definition: vehicle.h:1648
tripoint sm_pos
Submap coordinates of the currently loaded submap (see game::m) that contains this vehicle.
Definition: vehicle.h:1633
bool tracking_on
Definition: vehicle.h:1723
point ms_to_sm_remain(int &x, int &y)
static constexpr int SEEY
Standard arguments for finding overmap terrain.
std::vector< std::pair< std::string, ot_match_type > > types

References map::add_vehicle(), overmapbuffer::add_vehicle(), vehicle::can_float(), omt_find_params::cant_see, overmapbuffer::find_all(), map::getabs(), map::getlocal(), map::load(), m, omt_find_params::min_distance, ms_to_sm_remain(), omt_find_params::must_see, overmap_buffer, vehicle::pos, random_entry(), rng(), map::save(), omt_find_params::search_range, SEEX, SEEY, vehicle::sm_pos, vehicle::tracking_on, type, omt_find_params::types, and tripoint::xy().

Referenced by start_game().

◆ pre_print_all_tile_info()

void game::pre_print_all_tile_info ( const tripoint lp,
const catacurses::window w_info,
int &  line,
int  last_line,
const visibility_variables cache 
)

Definition at line 6586 of file game.cpp.

6589{
6590 // get global area info according to look_around caret position
6591 // TODO: fix point types
6593 lp ) ) ) );
6594 // we only need the area name and then pass it to print_all_tile_info() function below
6595 const std::string area_name = cur_ter_m->get_name();
6596 print_all_tile_info( lp, w_info, area_name, 1, first_line, last_line, cache );
6597}
void print_all_tile_info(const tripoint &lp, const catacurses::window &w_look, const std::string &area_name, int column, int &line, int last_line, const visibility_variables &cache)
Definition: game.cpp:5761
point ms_to_omt_copy(point p)
coords::coord_point< tripoint, coords::origin::abs, coords::omt > tripoint_abs_omt
Definition: coordinates.h:493
std::string get_name() const
Definition: omdata.h:205

References oter_t::get_name(), map::getabs(), m, ms_to_omt_copy(), overmap_buffer, print_all_tile_info(), and overmapbuffer::ter().

Referenced by look_around().

◆ print_all_tile_info()

void game::print_all_tile_info ( const tripoint lp,
const catacurses::window w_look,
const std::string &  area_name,
int  column,
int &  line,
int  last_line,
const visibility_variables cache 
)

Definition at line 5761 of file game.cpp.

5766{
5767 visibility_type visibility = VIS_HIDDEN;
5768 const bool inbounds = m.inbounds( lp );
5769 if( inbounds ) {
5770 visibility = m.get_visibility( m.apparent_light_at( lp, cache ), cache );
5771 }
5772 const Creature *creature = critter_at( lp, true );
5773 switch( visibility ) {
5774 case VIS_CLEAR: {
5775 const optional_vpart_position vp = m.veh_at( lp );
5776 print_terrain_info( lp, w_look, area_name, column, line );
5777 print_fields_info( lp, w_look, column, line );
5778 print_trap_info( lp, w_look, column, line );
5779 print_creature_info( creature, w_look, column, line, last_line );
5780 print_vehicle_info( veh_pointer_or_null( vp ), vp ? vp->part_index() : -1, w_look, column, line,
5781 last_line );
5782 print_items_info( lp, w_look, column, line, last_line );
5783 print_graffiti_info( lp, w_look, column, line, last_line );
5784 }
5785 break;
5786 case VIS_BOOMER:
5787 case VIS_BOOMER_DARK:
5788 case VIS_DARK:
5789 case VIS_LIT:
5790 case VIS_HIDDEN:
5791 print_visibility_info( w_look, column, line, visibility );
5792
5793 if( creature != nullptr ) {
5794 std::vector<std::string> buf;
5795 if( u.sees_with_infrared( *creature ) ) {
5796 creature->describe_infrared( buf );
5797 } else if( u.sees_with_specials( *creature ) ) {
5798 creature->describe_specials( buf );
5799 }
5800 for( const std::string &s : buf ) {
5801 mvwprintw( w_look, point( 1, ++line ), s );
5802 }
5803 }
5804 break;
5805 }
5806 if( !inbounds ) {
5807 return;
5808 }
5809 auto this_sound = sounds::sound_at( lp );
5810 if( !this_sound.empty() ) {
5811 mvwprintw( w_look, point( 1, ++line ), _( "You heard %s from here." ), this_sound );
5812 } else {
5813 // Check other z-levels
5814 tripoint tmp = lp;
5815 for( tmp.z = -OVERMAP_DEPTH; tmp.z <= OVERMAP_HEIGHT; tmp.z++ ) {
5816 if( tmp.z == lp.z ) {
5817 continue;
5818 }
5819
5820 auto zlev_sound = sounds::sound_at( tmp );
5821 if( !zlev_sound.empty() ) {
5822 mvwprintw( w_look, point( 1, ++line ), tmp.z > lp.z ?
5823 _( "You heard %s from above." ) : _( "You heard %s from below." ), zlev_sound );
5824 }
5825 }
5826 }
5827}
bool sees_with_specials(const Creature &critter) const
Definition: character.cpp:6364
bool sees_with_infrared(const Creature &critter) const
Check whether the this player can see the other creature with infrared.
void print_fields_info(const tripoint &lp, const catacurses::window &w_look, int column, int &line)
Definition: game.cpp:5934
void print_terrain_info(const tripoint &lp, const catacurses::window &w_look, const std::string &area_name, int column, int &line)
Definition: game.cpp:5858
void print_graffiti_info(const tripoint &lp, const catacurses::window &w_look, int column, int &line, int last_line)
Definition: game.cpp:6028
void print_creature_info(const Creature *creature, const catacurses::window &w_look, int column, int &line, int last_line)
Definition: game.cpp:5972
void print_vehicle_info(const vehicle *veh, int veh_part, const catacurses::window &w_look, int column, int &line, int last_line)
Definition: game.cpp:5981
void print_items_info(const tripoint &lp, const catacurses::window &w_look, int column, int &line, int last_line)
Definition: game.cpp:5990
void print_visibility_info(const catacurses::window &w_look, int column, int &line, visibility_type visibility)
Definition: game.cpp:5829
void print_trap_info(const tripoint &lp, const catacurses::window &w_look, int column, int &line)
Definition: game.cpp:5952
void line(map *m, const ter_id &type, point p1, point p2)
Definition: mapgen.cpp:6290
std::string sound_at(const tripoint &location)
Definition: sounds.cpp:606

References _, map::apparent_light_at(), creature, critter_at(), map::get_visibility(), map::inbounds(), line(), m, catacurses::mvwprintw(), OVERMAP_DEPTH, OVERMAP_HEIGHT, print_creature_info(), print_fields_info(), print_graffiti_info(), print_items_info(), print_terrain_info(), print_trap_info(), print_vehicle_info(), print_visibility_info(), Character::sees_with_infrared(), Character::sees_with_specials(), sounds::sound_at(), u, map::veh_at(), veh_pointer_or_null(), VIS_BOOMER, VIS_BOOMER_DARK, VIS_CLEAR, VIS_DARK, VIS_HIDDEN, VIS_LIT, and tripoint::z.

Referenced by pre_print_all_tile_info().

◆ print_creature_info()

void game::print_creature_info ( const Creature creature,
const catacurses::window w_look,
int  column,
int &  line,
int  last_line 
)
private

Definition at line 5972 of file game.cpp.

5974{
5975 int vLines = last_line - line;
5976 if( creature != nullptr && ( u.sees( *creature ) || creature == &u ) ) {
5977 line = creature->print_info( w_look, ++line, vLines, column );
5978 }
5979}

References creature, line(), Character::sees(), and u.

Referenced by print_all_tile_info().

◆ print_fields_info()

void game::print_fields_info ( const tripoint lp,
const catacurses::window w_look,
int  column,
int &  line 
)
private

Definition at line 5934 of file game.cpp.

5936{
5937 const field &tmpfield = m.field_at( lp );
5938 for( auto &fld : tmpfield ) {
5939 const field_entry &cur = fld.second;
5940 if( fld.first.obj().has_fire && ( m.has_flag( TFLAG_FIRE_CONTAINER, lp ) ||
5941 m.ter( lp ) == t_pit_shallow || m.ter( lp ) == t_pit ) ) {
5942 const int max_width = getmaxx( w_look ) - column - 2;
5943 int lines = fold_and_print( w_look, point( column, ++line ), max_width, cur.color(),
5944 get_fire_fuel_string( lp ) ) - 1;
5945 line += lines;
5946 } else {
5947 mvwprintz( w_look, point( column, ++line ), cur.color(), cur.name() );
5948 }
5949 }
5950}
An active or passive effect existing on a tile.
Definition: field.h:20
nc_color color() const
Definition: field.cpp:94
std::string name() const
Definition: field.h:84
A variable sized collection of field entries on a given map square.
Definition: field.h:131
ter_id t_pit_shallow
Definition: mapdata.cpp:628
ter_id t_pit
Definition: mapdata.cpp:628

References field_entry::color(), map::field_at(), fold_and_print(), get_fire_fuel_string(), catacurses::getmaxx(), map::has_flag(), line(), m, mvwprintz(), field_entry::name(), t_pit, t_pit_shallow, map::ter(), and TFLAG_FIRE_CONTAINER.

Referenced by print_all_tile_info().

◆ print_graffiti_info()

void game::print_graffiti_info ( const tripoint lp,
const catacurses::window w_look,
int  column,
int &  line,
int  last_line 
)
private

Definition at line 6028 of file game.cpp.

6031{
6032 if( line > last_line ) {
6033 return;
6034 }
6035
6036 const int max_width = getmaxx( w_look ) - column - 2;
6037 if( m.has_graffiti_at( lp ) ) {
6038 fold_and_print( w_look, point( column, ++line ), max_width, c_light_gray,
6039 m.ter( lp ) == t_grave_new ? _( "Graffiti: %s" ) : _( "Inscription: %s" ),
6040 m.graffiti_at( lp ) );
6041 }
6042}
ter_id t_grave_new
Definition: mapdata.cpp:628

References _, c_light_gray, fold_and_print(), catacurses::getmaxx(), map::graffiti_at(), map::has_graffiti_at(), line(), m, t_grave_new, and map::ter().

Referenced by print_all_tile_info().

◆ print_items_info()

void game::print_items_info ( const tripoint lp,
const catacurses::window w_look,
int  column,
int &  line,
int  last_line 
)
private

Definition at line 5990 of file game.cpp.

5994{
5995 if( !m.sees_some_items( lp, u ) ) {
5996 return;
5997 } else if( m.has_flag( "CONTAINER", lp ) && !m.could_see_items( lp, u ) ) {
5998 mvwprintw( w_look, point( column, ++line ), _( "You cannot see what is inside of it." ) );
5999 } else if( u.has_effect( effect_blind ) || u.worn_with_flag( "BLIND" ) ) {
6000 mvwprintz( w_look, point( column, ++line ), c_yellow,
6001 _( "There's something there, but you can't see what it is." ) );
6002 return;
6003 } else {
6004 std::map<std::string, int> item_names;
6005 for( auto &item : m.i_at( lp ) ) {
6006 ++item_names[item.tname()];
6007 }
6008
6009 const int max_width = getmaxx( w_look ) - column - 1;
6010 for( auto it = item_names.begin(); it != item_names.end(); ++it ) {
6011 // last line but not last item
6012 if( line + 1 >= last_line && std::next( it ) != item_names.end() ) {
6013 mvwprintz( w_look, point( column, ++line ), c_yellow, _( "More items here…" ) );
6014 break;
6015 }
6016
6017 if( it->second > 1 ) {
6018 trim_and_print( w_look, point( column, ++line ), max_width, c_white,
6019 pgettext( "%s is the name of the item. %d is the quantity of that item.", "%s [%d]" ),
6020 it->first.c_str(), it->second );
6021 } else {
6022 trim_and_print( w_look, point( column, ++line ), max_width, c_white, it->first );
6023 }
6024 }
6025 }
6026}
bool could_see_items(const tripoint &p, const Creature &who) const
Check if the creature could see items at p if there were any items.
Definition: map.cpp:4867
static const efftype_id effect_blind("blind")

References _, c_white, c_yellow, map::could_see_items(), effect_blind, catacurses::getmaxx(), Creature::has_effect(), map::has_flag(), map::i_at(), line(), m, catacurses::mvwprintw(), mvwprintz(), pgettext(), map::sees_some_items(), item::tname(), trim_and_print(), u, and Character::worn_with_flag().

Referenced by print_all_tile_info().

◆ print_terrain_info()

void game::print_terrain_info ( const tripoint lp,
const catacurses::window w_look,
const std::string &  area_name,
int  column,
int &  line 
)
private

Definition at line 5858 of file game.cpp.

5861{
5862 const int max_width = getmaxx( w_look ) - column - 1;
5863 int lines;
5864
5865 const auto fmt_tile_info = []( const tripoint & lp ) {
5866 map &here = get_map();
5867 std::string ret;
5868 if( debug_mode ) {
5869 ret += lp.to_string();
5870 ret += "\n";
5871 }
5872 ret += here.tername( lp );
5874 ret += colorize( string_format( " [%s]", here.ter( lp )->id ), c_light_blue );
5875 }
5876 if( here.has_furn( lp ) ) {
5877 ret += string_format( "; %s", here.furnname( lp ) );
5879 ret += colorize( string_format( " [%s]", here.furn( lp )->id ), c_light_blue );
5880 }
5881 }
5882 return ret;
5883 };
5884
5885 std::string tile = string_format( "(%s) %s", area_name, fmt_tile_info( lp ) );
5886
5887 if( m.impassable( lp ) ) {
5888 lines = fold_and_print( w_look, point( column, line ), max_width, c_light_gray,
5889 _( "%s; Impassable" ),
5890 tile );
5891 } else {
5892 lines = fold_and_print( w_look, point( column, line ), max_width, c_light_gray,
5893 _( "%s; Movement cost %d" ),
5894 tile, m.move_cost( lp ) * 50 );
5895
5896 const auto ll = get_light_level( std::max( 1.0,
5897 LIGHT_AMBIENT_LIT - m.ambient_light_at( lp ) + 1.0 ) );
5898 mvwprintw( w_look, point( column, ++lines ), _( "Lighting: " ) );
5899 wprintz( w_look, ll.second, ll.first );
5900 }
5901
5902 std::string signage = m.get_signage( lp );
5903 if( !signage.empty() ) {
5904 trim_and_print( w_look, point( column, ++lines ), max_width, c_dark_gray,
5905 // NOLINTNEXTLINE(cata-text-style): the question mark does not end a sentence
5906 u.has_trait( trait_ILLITERATE ) ? _( "Sign: ???" ) : _( "Sign: %s" ), signage );
5907 }
5908
5909 if( m.has_zlevels() && lp.z > -OVERMAP_DEPTH && !m.has_floor( lp ) ) {
5910 // Print info about stuff below
5911 tripoint below( lp.xy(), lp.z - 1 );
5912 std::string tile_below = fmt_tile_info( below );
5913
5914 if( !m.has_floor_or_support( lp ) ) {
5915 fold_and_print( w_look, point( column, ++lines ), max_width, c_dark_gray,
5916 _( "Below: %s; No support" ),
5917 tile_below );
5918 } else {
5919 fold_and_print( w_look, point( column, ++lines ), max_width, c_dark_gray,
5920 _( "Below: %s; Walkable" ),
5921 tile_below );
5922 }
5923 }
5924
5925 int map_features = fold_and_print( w_look, point( column, ++lines ), max_width, c_dark_gray,
5926 m.features( lp ) );
5927 fold_and_print( w_look, point( column, ++lines ), max_width, c_light_gray, _( "Coverage: %d%%" ),
5928 m.coverage( lp ) );
5929 if( line < lines ) {
5930 line = lines + map_features - 1;
5931 }
5932}
bool has_floor_or_support(const tripoint &p) const
Definition: map.cpp:2121
float ambient_light_at(const tripoint &p) const
Definition: lightmap.cpp:682
std::string features(const tripoint &p)
Definition: map.cpp:1779
int coverage(const tripoint &p) const
Returns coverage value of the tile.
Definition: map.cpp:6384
int move_cost(const tripoint &p, const vehicle *ignored_vehicle=nullptr) const
Calculate the cost to move past the tile at p.
Definition: map.cpp:1845
static constexpr float LIGHT_AMBIENT_LIT
Definition: lightmap.h:18
std::pair< std::string, nc_color > get_light_level(const float light)
Definition: output.cpp:1621

References _, map::ambient_light_at(), c_dark_gray, c_light_blue, c_light_gray, colorize(), map::coverage(), debug_mode, display_object_ids, map::features(), fold_and_print(), get_light_level(), get_map, map::get_signage(), catacurses::getmaxx(), map::has_floor(), map::has_floor_or_support(), Character::has_trait(), map::has_zlevels(), anonymous_namespace{iexamine_elevator.cpp}::elevator::here(), map::impassable(), LIGHT_AMBIENT_LIT, line(), m, map::move_cost(), catacurses::mvwprintw(), OVERMAP_DEPTH, cata::hash64_detail::ret, string_format(), tripoint::to_string(), trait_ILLITERATE, trim_and_print(), u, wprintz(), tripoint::xy(), and tripoint::z.

Referenced by print_all_tile_info().

◆ print_trap_info()

void game::print_trap_info ( const tripoint lp,
const catacurses::window w_look,
int  column,
int &  line 
)
private

Definition at line 5952 of file game.cpp.

5955{
5956 const trap &tr = m.tr_at( lp );
5957 if( tr.can_see( lp, u ) ) {
5958 partial_con *pc = m.partial_con_at( lp );
5959 std::string tr_name;
5960 if( pc && tr.loadid == tr_unfinished_construction ) {
5961 const construction &built = pc->id.obj();
5962 tr_name = string_format( _( "Unfinished task: %s, %d%% complete" ), built.group->name(),
5963 pc->counter / 100000 );
5964 } else {
5965 tr_name = tr.name();
5966 }
5967
5968 mvwprintz( w_look, point( column, ++line ), tr.color, tr_name );
5969 }
5970}
partial_con * partial_con_at(const tripoint &p)
Definition: map.cpp:5274
static const trap_str_id tr_unfinished_construction("tr_unfinished_construction")
std::string name() const
construction_group_str_id group
Definition: construction.h:50
construction_id id
nc_color color
Definition: trap.h:93

References _, trap::can_see(), trap::color, partial_con::counter, construction::group, partial_con::id, line(), trap::loadid, m, mvwprintz(), construction_group::name(), trap::name(), int_id< T >::obj(), map::partial_con_at(), string_format(), map::tr_at(), tr_unfinished_construction, and u.

Referenced by print_all_tile_info().

◆ print_vehicle_info()

void game::print_vehicle_info ( const vehicle veh,
int  veh_part,
const catacurses::window w_look,
int  column,
int &  line,
int  last_line 
)
private

Definition at line 5981 of file game.cpp.

5983{
5984 if( veh ) {
5985 mvwprintw( w_look, point( column, ++line ), _( "There is a %s there. Parts:" ), veh->name );
5986 line = veh->print_part_list( w_look, ++line, last_line, getmaxx( w_look ), veh_part );
5987 }
5988}
int print_part_list(const catacurses::window &win, int y1, int max_y, int width, int p, int hl=-1, bool detail=false) const
Prints a list of all parts to the screen inside of a boxed window, possibly highlighting a selected o...

References _, catacurses::getmaxx(), line(), catacurses::mvwprintw(), vehicle::name, and vehicle::print_part_list().

Referenced by print_all_tile_info().

◆ print_visibility_info()

void game::print_visibility_info ( const catacurses::window w_look,
int  column,
int &  line,
visibility_type  visibility 
)
private

Definition at line 5829 of file game.cpp.

5831{
5832 const char *visibility_message = nullptr;
5833 switch( visibility ) {
5834 case VIS_CLEAR:
5835 visibility_message = _( "Clearly visible." );
5836 break;
5837 case VIS_BOOMER:
5838 visibility_message = _( "A bright pink blur." );
5839 break;
5840 case VIS_BOOMER_DARK:
5841 visibility_message = _( "A pink blur." );
5842 break;
5843 case VIS_DARK:
5844 visibility_message = _( "Darkness." );
5845 break;
5846 case VIS_LIT:
5847 visibility_message = _( "Bright light." );
5848 break;
5849 case VIS_HIDDEN:
5850 visibility_message = _( "Unseen." );
5851 break;
5852 }
5853
5854 mvwprintw( w_look, point( line, column ), visibility_message );
5855 line += 2;
5856}

References _, line(), catacurses::mvwprintw(), VIS_BOOMER, VIS_BOOMER_DARK, VIS_CLEAR, VIS_DARK, VIS_HIDDEN, and VIS_LIT.

Referenced by print_all_tile_info().

◆ process_activity()

void game::process_activity ( )
private

Definition at line 1650 of file game.cpp.

1651{
1652 if( !u.activity ) {
1653 return;
1654 }
1655
1656 while( u.moves > 0 && u.activity ) {
1657 u.activity.do_turn( u );
1658 }
1659}
void do_turn(player &p)
Performs the activity for a single turn.

References Character::activity, player_activity::do_turn(), Creature::moves, and u.

Referenced by do_turn().

◆ process_artifact()

void game::process_artifact ( item it,
player p 
)

Definition at line 11376 of file game.cpp.

11377{
11378 const bool worn = p.is_worn( it );
11379 const bool wielded = ( &it == &p.primary_weapon() );
11380 std::vector<art_effect_passive> effects = it.type->artifact->effects_carried;
11381 if( worn ) {
11382 const std::vector<art_effect_passive> &ew = it.type->artifact->effects_worn;
11383 effects.insert( effects.end(), ew.begin(), ew.end() );
11384 }
11385 if( wielded ) {
11386 const std::vector<art_effect_passive> &ew = it.type->artifact->effects_wielded;
11387 effects.insert( effects.end(), ew.begin(), ew.end() );
11388 }
11389
11390 if( it.is_tool() ) {
11391 // Recharge it if necessary
11392 if( it.ammo_remaining() < it.ammo_capacity() && calendar::once_every( 1_minutes ) ) {
11393 //Before incrementing charge, check that any extra requirements are met
11394 if( check_art_charge_req( it ) ) {
11395 switch( it.type->artifact->charge_type ) {
11396 case ARTC_NULL:
11397 case NUM_ARTCS:
11398 break; // dummy entries
11399 case ARTC_TIME:
11400 // Once per hour
11401 if( calendar::once_every( 1_hours ) ) {
11402 it.charges++;
11403 }
11404 break;
11405 case ARTC_SOLAR:
11406 if( calendar::once_every( 10_minutes ) &&
11407 is_in_sunlight( p.pos() ) ) {
11408 it.charges++;
11409 }
11410 break;
11411 // Artifacts can inflict pain even on Deadened folks.
11412 // Some weird Lovecraftian thing. ;P
11413 // (So DON'T route them through mod_pain!)
11414 case ARTC_PAIN:
11415 if( calendar::once_every( 1_minutes ) ) {
11416 add_msg( m_bad, _( "You suddenly feel sharp pain for no reason." ) );
11417 p.mod_pain_noresist( 3 * rng( 1, 3 ) );
11418 it.charges++;
11419 }
11420 break;
11421 case ARTC_HP:
11422 if( calendar::once_every( 1_minutes ) ) {
11423 add_msg( m_bad, _( "You feel your body decaying." ) );
11424 p.hurtall( 1, nullptr );
11425 it.charges++;
11426 }
11427 break;
11428 case ARTC_FATIGUE:
11429 if( calendar::once_every( 1_minutes ) ) {
11430 add_msg( m_bad, _( "You feel fatigue seeping into your body." ) );
11431 u.mod_fatigue( 3 * rng( 1, 3 ) );
11432 u.mod_stamina( -90 * rng( 1, 3 ) * rng( 1, 3 ) * rng( 2, 3 ) );
11433 it.charges++;
11434 }
11435 break;
11436 // Portals are energetic enough to charge the item.
11437 // Tears in reality are consumed too, but can't charge it.
11438 case ARTC_PORTAL:
11439 for( const tripoint &dest : m.points_in_radius( p.pos(), 1 ) ) {
11441 if( m.tr_at( dest ).loadid == tr_portal ) {
11442 add_msg( m_good, _( "The portal collapses!" ) );
11443 m.remove_trap( dest );
11444 it.charges++;
11445 break;
11446 }
11447 }
11448 break;
11449 }
11450 }
11451 }
11452 }
11453
11454 for( const art_effect_passive &i : effects ) {
11455 switch( i ) {
11456 case AEP_STR_UP:
11457 p.mod_str_bonus( +4 );
11458 break;
11459 case AEP_DEX_UP:
11460 p.mod_dex_bonus( +4 );
11461 break;
11462 case AEP_PER_UP:
11463 p.mod_per_bonus( +4 );
11464 break;
11465 case AEP_INT_UP:
11466 p.mod_int_bonus( +4 );
11467 break;
11468 case AEP_ALL_UP:
11469 p.mod_str_bonus( +2 );
11470 p.mod_dex_bonus( +2 );
11471 p.mod_per_bonus( +2 );
11472 p.mod_int_bonus( +2 );
11473 break;
11474 case AEP_SPEED_UP:
11475 // Handled in player::current_speed()
11476 break;
11477
11478 case AEP_PBLUE:
11479 if( p.get_rad() > 0 ) {
11480 p.mod_rad( -1 );
11481 }
11482 break;
11483
11484 case AEP_SMOKE:
11485 if( one_in( 10 ) ) {
11486 tripoint pt( p.posx() + rng( -1, 1 ),
11487 p.posy() + rng( -1, 1 ),
11488 p.posz() );
11489 m.add_field( pt, fd_smoke, rng( 1, 3 ) );
11490 }
11491 break;
11492
11493 case AEP_SNAKES:
11494 break; // Handled in player::hit()
11495
11496 case AEP_EXTINGUISH:
11497 for( const tripoint &dest : m.points_in_radius( p.pos(), 1 ) ) {
11498 m.mod_field_age( dest, fd_fire, -1_turns );
11499 }
11500 break;
11501
11502 case AEP_FUN:
11503 //Bonus fluctuates, wavering between 0 and 30-ish - usually around 12
11504 p.add_morale( MORALE_FEELING_GOOD, rng( 1, 2 ) * rng( 2, 3 ), 0, 3_turns, 0_turns, false );
11505 break;
11506
11507 case AEP_HUNGER:
11508 if( one_in( 100 ) ) {
11509 p.mod_stored_kcal( -10 );
11510 }
11511 break;
11512
11513 case AEP_THIRST:
11514 if( one_in( 120 ) ) {
11515 p.mod_thirst( 1 );
11516 }
11517 break;
11518
11519 case AEP_EVIL:
11520 if( one_in( 150 ) ) { // Once every 15 minutes, on average
11521 p.add_effect( effect_evil, 30_minutes );
11522 if( it.is_armor() ) {
11523 if( !worn ) {
11524 add_msg( _( "You have an urge to wear the %s." ),
11525 it.tname() );
11526 }
11527 } else if( !wielded ) {
11528 add_msg( _( "You have an urge to wield the %s." ),
11529 it.tname() );
11530 }
11531 }
11532 break;
11533
11534 case AEP_SCHIZO:
11535 break; // Handled in player::suffer()
11536
11537 case AEP_RADIOACTIVE:
11538 if( one_in( 4 ) ) {
11539 p.irradiate( 1.0f );
11540 }
11541 break;
11542
11543 case AEP_STR_DOWN:
11544 p.mod_str_bonus( -3 );
11545 break;
11546
11547 case AEP_DEX_DOWN:
11548 p.mod_dex_bonus( -3 );
11549 break;
11550
11551 case AEP_PER_DOWN:
11552 p.mod_per_bonus( -3 );
11553 break;
11554
11555 case AEP_INT_DOWN:
11556 p.mod_int_bonus( -3 );
11557 break;
11558
11559 case AEP_ALL_DOWN:
11560 p.mod_str_bonus( -2 );
11561 p.mod_dex_bonus( -2 );
11562 p.mod_per_bonus( -2 );
11563 p.mod_int_bonus( -2 );
11564 break;
11565
11566 case AEP_SPEED_DOWN:
11567 break; // Handled in player::current_speed()
11568
11569 default:
11570 //Suppress warnings
11571 break;
11572 }
11573 }
11574 // Recalculate, as it might have changed (by mod_*_bonus above)
11575 p.str_cur = p.get_str();
11576 p.int_cur = p.get_int();
11577 p.dex_cur = p.get_dex();
11578 p.per_cur = p.get_per();
11579}
@ ARTC_PORTAL
Definition: artifact.h:69
@ ARTC_FATIGUE
Definition: artifact.h:68
@ ARTC_NULL
Definition: artifact.h:63
@ ARTC_SOLAR
Definition: artifact.h:65
@ NUM_ARTCS
Definition: artifact.h:70
@ ARTC_HP
Definition: artifact.h:67
@ ARTC_TIME
Definition: artifact.h:64
@ ARTC_PAIN
Definition: artifact.h:66
virtual void mod_per_bonus(int nper)
Definition: character.cpp:4209
virtual void mod_dex_bonus(int ndex)
Definition: character.cpp:4204
int str_cur
Definition: character.h:264
void mod_rad(int mod)
Definition: character.cpp:7085
virtual int get_dex() const
Definition: character.cpp:4093
virtual void mod_stored_kcal(int nkcal)
Modifiers for need values exclusive to characters.
Definition: character.cpp:4324
bool is_worn(const item &thing) const
Definition: character.h:1097
virtual int get_int() const
Definition: character.cpp:4101
virtual void mod_fatigue(int nfatigue)
Definition: character.cpp:4455
virtual void mod_str_bonus(int nstr)
Definition: character.cpp:4199
int int_cur
Definition: character.h:266
int get_rad() const
Definition: character.cpp:7075
void add_morale(const morale_type &type, int bonus, int max_bonus=0, const time_duration &duration=1_hours, const time_duration &decay_start=30_minutes, bool capped=false, const itype *item_type=nullptr)
Definition: character.cpp:9098
virtual int get_per() const
Definition: character.cpp:4097
void hurtall(int dam, Creature *source, bool disturb=true)
Hurts all body parts for dam, no armor reduction.
Definition: character.cpp:8668
bool irradiate(float rads, bool bypass=false)
Handles mitigation and application of radiation.
Definition: suffer.cpp:1589
virtual void mod_int_bonus(int nint)
Definition: character.cpp:4214
virtual void mod_pain_noresist(int npain)
Definition: creature.cpp:1393
bool is_in_sunlight(const tripoint &p)
Returns true if p is outdoors and it is sunny.
Definition: game.cpp:4854
bool is_tool() const
Definition: item.cpp:6968
int charges
Definition: item.h:2209
bool is_armor() const
Definition: item.cpp:6714
bool add_field(const tripoint &p, const field_type_id &type_id, int intensity=INT_MAX, const time_duration &age=0_turns, bool hit_player=true)
Add field entry at point, or set intensity if present.
Definition: map.cpp:5536
time_duration mod_field_age(const tripoint &p, const field_type_id &type, const time_duration &offset)
Increment/decrement age of field entry at point.
Definition: map.cpp:5449
void remove_trap(const tripoint &p)
Definition: map.cpp:5394
art_effect_passive
Definition: enums.h:99
@ AEP_EXTINGUISH
Definition: enums.h:114
field_type_id fd_smoke
Definition: field_type.cpp:346
field_type_id fd_fatigue
Definition: field_type.cpp:354
static const efftype_id effect_evil("evil")
static const trap_str_id tr_portal("tr_portal")
const morale_type MORALE_FEELING_GOOD("morale_feeling_good")

References _, Creature::add_effect(), map::add_field(), Character::add_morale(), add_msg(), AEP_ALL_DOWN, AEP_ALL_UP, AEP_DEX_DOWN, AEP_DEX_UP, AEP_EVIL, AEP_EXTINGUISH, AEP_FUN, AEP_HUNGER, AEP_INT_DOWN, AEP_INT_UP, AEP_PBLUE, AEP_PER_DOWN, AEP_PER_UP, AEP_RADIOACTIVE, AEP_SCHIZO, AEP_SMOKE, AEP_SNAKES, AEP_SPEED_DOWN, AEP_SPEED_UP, AEP_STR_DOWN, AEP_STR_UP, AEP_THIRST, item::ammo_capacity(), item::ammo_remaining(), ARTC_FATIGUE, ARTC_HP, ARTC_NULL, ARTC_PAIN, ARTC_PORTAL, ARTC_SOLAR, ARTC_TIME, itype::artifact, item::charges, check_art_charge_req(), anonymous_namespace{iexamine_elevator.cpp}::elevator::dest(), Character::dex_cur, effect_evil, fd_fatigue, fd_fire, fd_smoke, Character::get_dex(), Character::get_int(), Character::get_per(), Character::get_rad(), Character::get_str(), Character::hurtall(), Character::int_cur, Character::irradiate(), item::is_armor(), is_in_sunlight(), item::is_tool(), Character::is_worn(), trap::loadid, m, m_bad, m_good, Character::mod_dex_bonus(), Character::mod_fatigue(), map::mod_field_age(), Character::mod_int_bonus(), Creature::mod_pain_noresist(), Character::mod_per_bonus(), Character::mod_rad(), Character::mod_stamina(), Character::mod_stored_kcal(), Character::mod_str_bonus(), Character::mod_thirst(), MORALE_FEELING_GOOD, NUM_ARTCS, calendar::once_every(), one_in(), Character::per_cur, map::points_in_radius(), Character::pos(), Character::posx(), Character::posy(), Character::posz(), Character::primary_weapon(), map::remove_field(), map::remove_trap(), rng(), Character::str_cur, item::tname(), map::tr_at(), tr_portal, item::type, and u.

◆ process_voluntary_act_interrupt()

void game::process_voluntary_act_interrupt ( )
private

Definition at line 1610 of file game.cpp.

1611{
1612 if( u.has_effect( effect_sleep ) ) {
1613 // Can't interrupt
1614 return;
1615 }
1616
1617 bool has_activity = u.activity && u.activity.moves_left > 0;
1618 bool is_travelling = u.has_destination() && !u.omt_path.empty();
1619
1620 if( !has_activity && !is_travelling ) {
1621 // Nohing to interrupt
1622 return;
1623 }
1624
1625 // Key poll may be quite expensive, so limit it to 10 times per second.
1626 static auto last_poll = std::chrono::steady_clock::now();
1627 auto now = std::chrono::steady_clock::now();
1628 int64_t difference = std::chrono::duration_cast<std::chrono::milliseconds>
1629 ( now - last_poll ).count();
1630
1631 if( difference > 100 ) {
1633 last_poll = now;
1634 }
1635
1636 // If player is performing a task and a monster is dangerously close, warn them
1637 // regardless of previous safemode warnings.
1638 // Distraction Manager can change this.
1639 if( ( has_activity || is_travelling ) && !u.has_activity( activity_id( "ACT_AIM" ) ) &&
1641 Creature *hostile_critter = is_hostile_very_close();
1642 if( hostile_critter != nullptr ) {
1644 string_format( _( "The %s is dangerously close!" ),
1645 hostile_critter->get_name() ) );
1646 }
1647 }
1648}
bool has_activity(const activity_id &type) const
Check if player currently has a given activity.
Definition: character.cpp:9229
virtual std::string get_name() const =0
void handle_key_blocking_activity()
Definition: game.cpp:1971
int moves_left
The number of moves remaining in this activity before it is complete.

References _, Character::activity, cancel_activity_or_ignore_query(), effect_sleep, Creature::get_name(), handle_key_blocking_activity(), Character::has_activity(), Character::has_destination(), Creature::has_effect(), hostile_spotted_near, player_activity::is_distraction_ignored(), is_hostile_very_close(), player_activity::moves_left, Character::omt_path, string_format(), and u.

Referenced by do_turn().

◆ prompt_dangerous_tile()

bool game::prompt_dangerous_tile ( const tripoint dest_loc) const

Definition at line 8724 of file game.cpp.

8725{
8726 static const iexamine_function ledge_examine = iexamine_function_from_string( "ledge" );
8727 std::vector<std::string> harmful_stuff = get_dangerous_tile( dest_loc );
8728
8729 if( harmful_stuff.empty() ) {
8730 return true;
8731 }
8732
8733 if( !( harmful_stuff.size() == 1 && m.tr_at( dest_loc ).loadid == tr_ledge ) ) {
8734 return query_yn( _( "Really step into %s?" ), enumerate_as_string( harmful_stuff ) ) ;
8735 }
8736
8737 if( !u.is_mounted() ) {
8738 ledge_examine( u, dest_loc );
8739 return false;
8740 }
8741
8742 add_msg( m_warning, _( "Your %s refuses to move over that ledge!" ),
8743 u.mounted_creature->get_name() );
8744 return false;
8745}
iexamine_function iexamine_function_from_string(const std::string &function_name)
Given then name of one of the above functions, returns the matching function pointer.
Definition: iexamine.cpp:6210
void(*)(player &, const tripoint &) iexamine_function
Definition: iexamine.h:142

References _, add_msg(), enumerate_as_string(), get_dangerous_tile(), iexamine_function_from_string(), Character::is_mounted(), trap::loadid, m, m_warning, Character::mounted_creature, query_yn(), map::tr_at(), tr_ledge, and u.

Referenced by npc_menu(), and walk_move().

◆ quickload()

void game::quickload ( )
private

Definition at line 11344 of file game.cpp.

11345{
11346 const WORLDPTR active_world = world_generator->active_world;
11347 if( active_world == nullptr ) {
11348 return;
11349 }
11350
11351 if( active_world->save_exists( save_t::from_save_id( u.get_save_id() ) ) ) {
11352 if( moves_since_last_save != 0 ) { // See if we need to reload anything
11353 MAPBUFFER.clear();
11355 try {
11356 setup();
11357 } catch( const std::exception &err ) {
11358 debugmsg( "Error: %s", err.what() );
11359 }
11361 }
11362 } else {
11363 popup_getkey( _( "No saves for current character yet." ) );
11364 }
11365}
bool load(const std::string &world)
Attempt to load first valid save (if any) in world.
Definition: game.cpp:2516
void setup()
Definition: game.cpp:479
static save_t from_save_id(const std::string &save_id)
int popup_getkey(const char *const mes, Args &&... args)
Definition: output.h:457
bool save_exists(const save_t &name) const

References _, mapbuffer::clear(), overmapbuffer::clear(), debugmsg, save_t::from_save_id(), avatar::get_save_id(), load(), MAPBUFFER, moves_since_last_save, overmap_buffer, popup_getkey(), WORLD::save_exists(), setup(), u, and world_generator.

Referenced by handle_action().

◆ quicksave()

void game::quicksave ( )

Definition at line 11322 of file game.cpp.

11323{
11324 //Don't autosave if the player hasn't done anything since the last autosave/quicksave,
11325 if( !moves_since_last_save ) {
11326 return;
11327 }
11328 add_msg( m_info, _( "Saving game, this may take a while" ) );
11329
11331 popup.message( "%s", _( "Saving game, this may take a while" ) );
11334
11335 time_t now = time( nullptr ); //timestamp for start of saving procedure
11336
11337 //perform save
11338 save();
11339 //Now reset counters for autosaving, so we don't immediately autosave after a quicksave or autosave.
11341 last_save_timestamp = now;
11342}

References _, add_msg(), last_save_timestamp, m_info, moves_since_last_save, popup(), ui_manager::redraw(), refresh_display(), save(), and time.

Referenced by autosave(), and handle_action().

◆ reenter_fullscreen()

void game::reenter_fullscreen ( )

Definition at line 467 of file game.cpp.

468{
469 if( was_fullscreen ) {
470 if( !fullscreen ) {
472 }
473 }
474}

References fullscreen, toggle_fullscreen(), and was_fullscreen.

Referenced by list_items_monsters(), and look_around().

◆ reload_npcs()

void game::reload_npcs ( )

Unloads, then loads the NPCs.

Definition at line 879 of file game.cpp.

880{
881 // TODO: Make it not invoke the "on_unload" command for the NPCs that will be loaded anyway
882 // and not invoke "on_load" for those NPCs that avoided unloading this way.
883 unload_npcs();
884 load_npcs();
885}

References load_npcs(), and unload_npcs().

Referenced by load(), overmap_npc_move(), vertical_move(), and vertical_shift().

◆ reload_tileset()

void game::reload_tileset ( std::function< void(std::string)>  out)

Definition at line 431 of file game.cpp.

432{
433#if defined(TILES)
434 // Disable UIs below to avoid accessing the tile context during loading.
436 try {
437 tilecontext->reinit();
438 std::vector<mod_id> dummy;
439 tilecontext->load_tileset(
440 get_option<std::string>( "TILES" ),
441 world_generator->active_world ? world_generator->active_world->active_mod_order : dummy,
442 /*precheck=*/false,
443 /*force=*/true,
444 /*pump_events=*/true
445 );
446 tilecontext->do_tile_loading_report( out );
447 } catch( const std::exception &err ) {
448 popup( _( "Loading the tileset failed: %s" ), err.what() );
449 }
450 g->reset_zoom();
451 g->mark_main_ui_adaptor_resize();
452#endif // TILES
453}

References _, g, popup(), and world_generator.

Referenced by handle_action().

◆ remoteveh()

vehicle * game::remoteveh ( )

Returns the current remotely controlled vehicle.

Definition at line 2250 of file game.cpp.

2251{
2253 return remoteveh_cache;
2254 }
2256 std::stringstream remote_veh_string( u.get_value( "remote_controlling_vehicle" ) );
2257 if( remote_veh_string.str().empty() ||
2259 remoteveh_cache = nullptr;
2260 } else {
2261 tripoint vp;
2262 remote_veh_string >> vp.x >> vp.y >> vp.z;
2263 vehicle *veh = veh_pointer_or_null( m.veh_at( vp ) );
2264 if( veh && veh->fuel_left( itype_battery, true ) > 0 ) {
2265 remoteveh_cache = veh;
2266 } else {
2267 remoteveh_cache = nullptr;
2268 }
2269 }
2270 return remoteveh_cache;
2271}
vehicle * remoteveh_cache
Definition: game.h:1044
int fuel_left(const itype_id &ftype, bool recurse=false) const
Definition: vehicle.cpp:3361
static const bionic_id bio_remote("bio_remote")
static const itype_id itype_remotevehcontrol("remotevehcontrol")
static const itype_id itype_battery("battery")

References bio_remote, vehicle::fuel_left(), Creature::get_value(), Character::has_active_bionic(), Character::has_active_item(), itype_battery, itype_remotevehcontrol, m, remoteveh_cache, remoteveh_cache_time, calendar::turn, u, map::veh_at(), veh_pointer_or_null(), tripoint::x, tripoint::y, and tripoint::z.

Referenced by control_vehicle(), and handle_action().

◆ remove_npc_follower()

void game::remove_npc_follower ( const character_id id)

Remove follower id from follower set.

Definition at line 1880 of file game.cpp.

1881{
1882 follower_ids.erase( id );
1883 u.follower_ids.erase( id );
1884}

References follower_ids, player::follower_ids, and u.

Referenced by cleanup_dead().

◆ remove_zombie()

void game::remove_zombie ( const monster critter)

Definition at line 4734 of file game.cpp.

4735{
4736 critter_tracker->remove( critter );
4737}

References critter_tracker.

Referenced by despawn_monster(), disable_robot(), start_game(), and vertical_move().

◆ replace_stair_monsters()

void game::replace_stair_monsters ( )
private

Definition at line 10828 of file game.cpp.

10829{
10830 for( auto &elem : coming_to_stairs ) {
10831 elem.staircount = 0;
10832 const tripoint pnt( elem.pos().xy(), get_levz() );
10833 place_critter_around( make_shared_fast<monster>( elem ), pnt, 10 );
10834 }
10835
10836 coming_to_stairs.clear();
10837}
std::vector< monster > coming_to_stairs
Definition: game.h:982

References coming_to_stairs, get_levz(), and place_critter_around().

◆ reset_item_list_state()

void game::reset_item_list_state ( const catacurses::window window,
int  height,
bool  bRadiusSort 
)
private

Definition at line 7183 of file game.cpp.

7185{
7186 const int width = getmaxx( window );
7187 for( int i = 1; i < TERMX; i++ ) {
7188 if( i < width ) {
7189 mvwputch( window, point( i, 0 ), c_light_gray, LINE_OXOX ); // -
7190 mvwputch( window, point( i, TERMY - height - 1 ), c_light_gray,
7191 LINE_OXOX ); // -
7192 }
7193
7194 if( i < TERMY - height ) {
7195 mvwputch( window, point( 0, i ), c_light_gray, LINE_XOXO ); // |
7196 mvwputch( window, point( width - 1, i ), c_light_gray, LINE_XOXO ); // |
7197 }
7198 }
7199
7200 mvwputch( window, point_zero, c_light_gray, LINE_OXXO ); // |^
7201 mvwputch( window, point( width - 1, 0 ), c_light_gray, LINE_OOXX ); // ^|
7202
7203 mvwputch( window, point( 0, TERMY - height - 1 ), c_light_gray,
7204 LINE_XXXO ); // |-
7205 mvwputch( window, point( width - 1, TERMY - height - 1 ), c_light_gray,
7206 LINE_XOXX ); // -|
7207
7208 mvwprintz( window, point( 2, 0 ), c_light_green, "<Tab> " );
7209 wprintz( window, c_white, _( "Items" ) );
7210
7211 std::string sSort;
7212 if( bRadiusSort ) {
7213 //~ Sort type: distance.
7214 sSort = _( "<s>ort: dist" );
7215 } else {
7216 //~ Sort type: category.
7217 sSort = _( "<s>ort: cat" );
7218 }
7219
7220 int letters = utf8_width( sSort );
7221
7222 shortcut_print( window, point( getmaxx( window ) - letters, 0 ), c_white, c_light_green, sSort );
7223
7224 std::vector<std::string> tokens;
7225 if( !sFilter.empty() ) {
7226 tokens.emplace_back( _( "<R>eset" ) );
7227 }
7228
7229 tokens.emplace_back( _( "<E>xamine" ) );
7230 tokens.emplace_back( _( "<C>ompare" ) );
7231 tokens.emplace_back( _( "<F>ilter" ) );
7232 tokens.emplace_back( _( "<+/->Priority" ) );
7233
7234 int gaps = tokens.size() + 1;
7235 letters = 0;
7236 int n = tokens.size();
7237 for( int i = 0; i < n; i++ ) {
7238 letters += utf8_width( tokens[i] ) - 2; //length ignores < >
7239 }
7240
7241 int usedwidth = letters;
7242 const int gap_spaces = ( width - usedwidth ) / gaps;
7243 usedwidth += gap_spaces * gaps;
7244 point pos( gap_spaces + ( width - usedwidth ) / 2, TERMY - height - 1 );
7245
7246 for( int i = 0; i < n; i++ ) {
7247 pos.x += shortcut_print( window, pos, c_white, c_light_green,
7248 tokens[i] ) + gap_spaces;
7249 }
7250}
#define LINE_OOXX
Definition: output.h:43
#define LINE_OXXO
Definition: output.h:42

References _, c_light_gray, c_light_green, c_white, catacurses::getmaxx(), LINE_OOXX, LINE_OXOX, LINE_OXXO, LINE_XOXO, LINE_XOXX, LINE_XXXO, mvwprintz(), mvwputch(), point_zero, sFilter, shortcut_print(), TERMX, TERMY, utf8_width(), wprintz(), and point::x.

Referenced by list_items().

◆ reset_light_level()

void game::reset_light_level ( )

Definition at line 3573 of file game.cpp.

3574{
3575 for( float &lev : latest_lightlevels ) {
3576 lev = -std::numeric_limits<float>::max();
3577 }
3578}

References latest_lightlevels.

Referenced by do_turn(), and game().

◆ reset_npc_dispositions()

void game::reset_npc_dispositions ( )
private

Definition at line 2632 of file game.cpp.

2633{
2634 for( auto elem : follower_ids ) {
2635 shared_ptr_fast<npc> npc_to_get = overmap_buffer.find_npc( elem );
2636 if( !npc_to_get ) {
2637 continue;
2638 }
2639 npc *npc_to_add = npc_to_get.get();
2640 npc_to_add->chatbin.missions.clear();
2641 npc_to_add->chatbin.missions_assigned.clear();
2642 npc_to_add->mission = NPC_MISSION_NULL;
2643 npc_to_add->chatbin.mission_selected = nullptr;
2644 npc_to_add->set_attitude( NPCATT_NULL );
2645 npc_to_add->op_of_u.anger = 0;
2646 npc_to_add->op_of_u.fear = 0;
2647 npc_to_add->op_of_u.trust = 0;
2648 npc_to_add->op_of_u.value = 0;
2649 npc_to_add->op_of_u.owed = 0;
2650 npc_to_add->set_fac( faction_id( "no_faction" ) );
2652 npc_to_add->global_omt_location(),
2653 npc_to_add->getID() ) );
2654
2655 }
2656
2657}
void set_attitude(npc_attitude new_attitude)
Definition: npc.cpp:3168
npc_chatbin chatbin
Definition: npc.h:1294
void add_new_mission(mission *miss)
See npc_chatbin::add_new_mission.
Definition: npc.cpp:2662
npc_opinion op_of_u
Definition: npc.h:1293
void set_fac(const faction_id &id)
Definition: npc.cpp:478
std::vector< mission * > missions_assigned
Mission that have been assigned by this NPC to a player character.
Definition: npc.h:715
mission * mission_selected
The mission (if any) that we talk about right now.
Definition: npc.h:720
std::vector< mission * > missions
Missions that the NPC can give out.
Definition: npc.h:711
int value
Definition: npc.h:205
int trust
Definition: npc.h:203
int owed
Definition: npc.h:207
int fear
Definition: npc.h:204
int anger
Definition: npc.h:206

References npc::add_new_mission(), npc_opinion::anger, npc::chatbin, npc_opinion::fear, overmapbuffer::find_npc(), follower_ids, Character::getID(), Character::global_omt_location(), npc::mission, npc_chatbin::mission_selected, npc_chatbin::missions, npc_chatbin::missions_assigned, NPC_MISSION_NULL, NPCATT_NULL, npc::op_of_u, ORIGIN_ANY_NPC, overmap_buffer, npc_opinion::owed, mission::reserve_random(), npc::set_attitude(), npc::set_fac(), npc_opinion::trust, and npc_opinion::value.

Referenced by cleanup_at_end().

◆ reset_zoom()

void game::reset_zoom ( )

Definition at line 7098 of file game.cpp.

7099{
7100#if defined(TILES)
7102 rescale_tileset( tileset_zoom );
7103#endif // TILES
7104}

References DEFAULT_TILESET_ZOOM, and tileset_zoom.

◆ revive_corpse()

bool game::revive_corpse ( const tripoint p,
item it 
)

Revives a corpse at given location.

The monster type and some of its properties are deducted from the corpse. If reviving succeeds, the location is guaranteed to have a new monster there (see critter_at).

Parameters
pThe place where to put the revived monster.
itThe corpse item, it must be a valid corpse (see item::is_corpse).
Returns
Whether the corpse has actually been redivided. Reviving may fail for many reasons, including no space to put the monster, corpse being to much damaged etc. If the monster was revived, the caller should remove the corpse item. If reviving failed, the item is unchanged, as is the environment (no new monsters).

Definition at line 4864 of file game.cpp.

4865{
4866 if( !it.is_corpse() ) {
4867 debugmsg( "Tried to revive a non-corpse." );
4868 return false;
4869 }
4870 shared_ptr_fast<monster> newmon_ptr = make_shared_fast<monster>
4871 ( it.get_mtype()->id );
4872 monster &critter = *newmon_ptr;
4873 critter.init_from_item( it );
4874 if( critter.get_hp() < 1 ) {
4875 // Failed reanimation due to corpse being too burned
4876 return false;
4877 }
4878 if( it.has_flag( "FIELD_DRESS" ) || it.has_flag( "FIELD_DRESS_FAILED" ) ||
4879 it.has_flag( "QUARTERED" ) ) {
4880 // Failed reanimation due to corpse being butchered
4881 return false;
4882 }
4883
4884 critter.no_extra_death_drops = true;
4885 critter.add_effect( effect_downed, 5_turns, num_bp );
4886 for( const item &component : it.components ) {
4887 critter.corpse_components.push_back( component );
4888 }
4889
4890 if( it.get_var( "zlave" ) == "zlave" ) {
4891 critter.add_effect( effect_pacified, 1_turns, num_bp );
4892 critter.add_effect( effect_pet, 1_turns, num_bp );
4893 }
4894
4895 if( it.get_var( "no_ammo" ) == "no_ammo" ) {
4896 for( auto &ammo : critter.ammo ) {
4897 ammo.second = 0;
4898 }
4899 }
4900
4901 return place_critter_at( newmon_ptr, p );
4902}
monster * place_critter_at(const mtype_id &id, const tripoint &p)
Adds critters to the reality bubble, creating them if necessary.
Definition: game.cpp:4662
double get_var(const std::string &name, double default_value) const
Definition: item.cpp:1035
const mtype * get_mtype() const
Definition: item.cpp:6635
std::list< item > components
Definition: item.h:2172
bool has_flag(const std::string &flag) const
Definition: item.cpp:5330
bool is_corpse() const
Whether this is a corpse item.
Definition: item.cpp:6630
int get_hp(const bodypart_id &) const override
Definition: monster.cpp:2954
bool no_extra_death_drops
Definition: monster.h:480
std::vector< item > corpse_components
Definition: monster.h:457
void init_from_item(const item &itm)
Initialize values like speed / hp from data of an item.
Definition: monster.cpp:2824
static const efftype_id effect_downed("downed")
static const efftype_id effect_pacified("pacified")

References monster::add_effect(), monster::ammo, item::components, monster::corpse_components, debugmsg, effect_downed, effect_pacified, effect_pet, monster::get_hp(), item::get_mtype(), item::get_var(), item::has_flag(), mtype::id, monster::init_from_item(), item::is_corpse(), monster::no_extra_death_drops, num_bp, and place_critter_at().

◆ save()

bool game::save ( )

Returns false if saving failed.

Definition at line 2746 of file game.cpp.

2747{
2749 try {
2750 if( !save_player_data() ||
2752 !save_artifacts() ||
2753 !save_maps() ||
2754 !get_auto_pickup().save_character() ||
2756 !get_safemode().save_character() ||
2757 !cata::save_world_lua_state( g->get_world_base_save_path() + "/lua_state.json" ) ||
2758 !save_uistate_data( *this )
2759 ) {
2760 return false;
2761 } else {
2762 world_generator->last_world_name = world_generator->active_world->world_name;
2763 world_generator->last_character_name = u.name;
2764 world_generator->save_last_world_info();
2765 world_generator->active_world->add_save( save_t::from_save_id( u.get_save_id() ) );
2766 return true;
2767 }
2768 } catch( std::ios::failure &err ) {
2769 popup( _( "Failed to save game data" ) );
2770 return false;
2771 }
2772}
bool save_player_data()
Definition: game.cpp:2687
static bool save_uistate_data(const game &g)
Definition: game.cpp:2738
@ failure
Definition: behavior.h:20
bool save_world_lua_state(const std::string &)
Definition: catalua.cpp:64
void run_on_game_save_hooks(lua_state &state)
Definition: catalua.cpp:418

References _, behavior::failure, save_t::from_save_id(), g, get_auto_notes_settings(), get_auto_pickup(), DynamicDataLoader::get_instance(), get_safemode(), avatar::get_save_id(), Character::name, popup(), cata::run_on_game_save_hooks(), save(), save_artifacts(), save_factions_missions_npcs(), save_maps(), save_player_data(), save_uistate_data(), cata::save_world_lua_state(), u, and world_generator.

Referenced by handle_action(), quicksave(), and save().

◆ save_artifacts()

bool game::save_artifacts ( )
private

Definition at line 2668 of file game.cpp.

2669{
2670 std::string artfilename = get_world_base_save_path() + "/" + SAVE_ARTIFACTS;
2671 return ::save_artifacts( artfilename );
2672}
bool save_artifacts(const std::string &path)
Definition: artifact.cpp:1277
static const std::string SAVE_ARTIFACTS("artifacts.gsav")

References get_world_base_save_path(), SAVE_ARTIFACTS(), and save_artifacts().

Referenced by cleanup_at_end(), and save().

◆ save_cyborg()

void game::save_cyborg ( item cyborg,
const tripoint couch_pos,
player installer 
)

Turns Broken Cyborg monster into Cyborg NPC via surgery.

Definition at line 4925 of file game.cpp.

4926{
4927 int assist_bonus = installer.get_effect_int( effect_assisted );
4928
4929 float adjusted_skill = installer.bionics_adjusted_skill( skill_firstaid,
4932 -1 );
4933
4934 int damage = cyborg->damage();
4935 int dmg_lvl = cyborg->damage_level( 4 );
4936 int difficulty = 12;
4937
4938 if( damage != 0 ) {
4939
4940 popup( _( "WARNING: Patient's body is damaged. Difficulty of the procedure is increased by %s." ),
4941 dmg_lvl );
4942
4943 // Damage of the cyborg increases difficulty
4944 difficulty += dmg_lvl;
4945 }
4946
4947 int chance_of_success = bionic_manip_cos( adjusted_skill + assist_bonus, difficulty );
4948 int success = chance_of_success - rng( 1, 100 );
4949
4950 if( !g->u.query_yn(
4951 _( "WARNING: %i percent chance of SEVERE damage to all body parts! Continue anyway?" ),
4952 100 - static_cast<int>( chance_of_success ) ) ) {
4953 return;
4954 }
4955
4956 if( success > 0 ) {
4957 add_msg( m_good, _( "Successfully removed Personality override." ) );
4958 add_msg( m_bad, _( "Autodoc immediately destroys the CBM upon removal." ) );
4959
4960 delete_cyborg_item( g->m, couch_pos, cyborg );
4961
4962 const string_id<npc_template> npc_cyborg( "cyborg_rescued" );
4963 shared_ptr_fast<npc> tmp = make_shared_fast<npc>();
4964 tmp->load_npc_template( npc_cyborg );
4965 tmp->spawn_at_precise( { get_levx(), get_levy() }, couch_pos );
4967 tmp->hurtall( dmg_lvl * 10, nullptr );
4968 tmp->add_effect( effect_downed, rng( 1_turns, 4_turns ), num_bp, 0, true );
4969 load_npcs();
4970
4971 } else {
4972 const int failure_level = static_cast<int>( std::sqrt( std::abs( success ) * 4.0 * difficulty /
4973 adjusted_skill ) );
4974 const int fail_type = std::min( 5, failure_level );
4975 switch( fail_type ) {
4976 case 1:
4977 case 2:
4978 add_msg( m_info, _( "The removal fails." ) );
4979 add_msg( m_bad, _( "The body is damaged." ) );
4980 cyborg->set_damage( damage + 1000 );
4981 break;
4982 case 3:
4983 case 4:
4984 add_msg( m_info, _( "The removal fails badly." ) );
4985 add_msg( m_bad, _( "The body is badly damaged!" ) );
4986 cyborg->set_damage( damage + 2000 );
4987 break;
4988 case 5:
4989 add_msg( m_info, _( "The removal is a catastrophe." ) );
4990 add_msg( m_bad, _( "The body is destroyed!" ) );
4991 delete_cyborg_item( g->m, couch_pos, cyborg );
4992 break;
4993 default:
4994 break;
4995 }
4996
4997 }
4998
4999}
int bionic_manip_cos(float adjusted_skill, int bionic_difficulty)
Definition: bionics.cpp:1941
float bionics_adjusted_skill(const skill_id &most_important_skill, const skill_id &important_skill, const skill_id &least_important_skill, int skill_level=-1)
Calculate skill for (un)installing bionics.
Definition: bionics.cpp:1898
item & set_damage(int qty)
Filter setting damage constrained by min_damage and max_damage.
Definition: item.cpp:719
int damage_level(int max) const
Scale item damage to the given number of levels.
Definition: item.cpp:706
int damage() const
How much damage has the item sustained?
Definition: item.cpp:701
static const skill_id skill_computer("computer")
static void delete_cyborg_item(map &m, const tripoint &couch_pos, item *cyborg)
Definition: game.cpp:4904
static const efftype_id effect_assisted("assisted")
static const skill_id skill_electronics("electronics")
@ success
Definition: behavior.h:20

References _, add_msg(), bionic_manip_cos(), Character::bionics_adjusted_skill(), item::damage(), item::damage_level(), delete_cyborg_item(), effect_assisted, effect_downed, g, Creature::get_effect_int(), get_levx(), get_levy(), overmapbuffer::insert_npc(), load_npcs(), m_bad, m_good, m_info, num_bp, overmap_buffer, popup(), rng(), item::set_damage(), skill_computer, skill_electronics, skill_firstaid, and behavior::success.

◆ save_factions_missions_npcs()

bool game::save_factions_missions_npcs ( )
private

Definition at line 2660 of file game.cpp.

2661{
2662 std::string masterfile = get_world_base_save_path() + "/" + SAVE_MASTER;
2663 return write_to_file( masterfile, [&]( std::ostream & fout ) {
2664 serialize_master( fout );
2665 }, _( "factions data" ) );
2666}
void write_to_file(const std::string &path, const std::function< void(std::ostream &)> &writer)
void serialize_master(std::ostream &fout)
Definition: savegame.cpp:1243

References _, get_world_base_save_path(), SAVE_MASTER(), serialize_master(), and write_to_file().

Referenced by cleanup_at_end(), and save().

◆ save_maps()

bool game::save_maps ( )
private

Definition at line 2674 of file game.cpp.

2675{
2676 try {
2677 m.save();
2678 overmap_buffer.save(); // can throw
2679 MAPBUFFER.save(); // can throw
2680 return true;
2681 } catch( const std::exception &err ) {
2682 popup( _( "Failed to save the maps: %s" ), err.what() );
2683 return false;
2684 }
2685}
void save(bool delete_after_save=false)
Store all submaps in this instance into savefiles.
Definition: mapbuffer.cpp:98

References _, m, MAPBUFFER, overmap_buffer, popup(), map::save(), overmapbuffer::save(), and mapbuffer::save().

Referenced by cleanup_at_end(), and save().

◆ save_player_data()

bool game::save_player_data ( )
private

Definition at line 2687 of file game.cpp.

2688{
2689 const std::string playerfile = get_player_base_save_path();
2690
2691 const bool saved_data = write_to_file( playerfile + SAVE_EXTENSION, [&]( std::ostream & fout ) {
2692 serialize( fout );
2693 }, _( "player data" ) );
2694 const bool saved_map_memory = u.save_map_memory();
2695 const bool saved_log = write_to_file( playerfile + SAVE_EXTENSION_LOG, [&](
2696 std::ostream & fout ) {
2697 fout << memorial().dump();
2698 }, _( "player memorial" ) );
2699#if defined(__ANDROID__)
2700 const bool saved_shortcuts = write_to_file( playerfile + SAVE_EXTENSION_SHORTCUTS, [&](
2701 std::ostream & fout ) {
2702 save_shortcuts( fout );
2703 }, _( "quick shortcuts" ) );
2704#endif
2705 const bool saved_diary = u.get_avatar_diary()->store();
2706 return saved_data && saved_map_memory && saved_log && saved_diary
2707#if defined(__ANDROID__)
2708 && saved_shortcuts
2709#endif
2710 ;
2711}
bool save_map_memory()
Definition: avatar.cpp:133
bool store()
Definition: diary.cpp:760
std::string get_player_base_save_path() const
Base path for saving player data.
Definition: game.cpp:12061
void serialize(std::ostream &fout)
Saving and loading functions.
Definition: savegame.cpp:69
std::string dump() const
Concatenates all of the memorial log entries, delimiting them with newlines, and returns the resultin...

References _, memorial_logger::dump(), avatar::get_avatar_diary(), get_player_base_save_path(), memorial(), SAVE_EXTENSION(), SAVE_EXTENSION_LOG(), SAVE_EXTENSION_SHORTCUTS(), avatar::save_map_memory(), serialize(), diary::store(), u, and write_to_file().

Referenced by save().

◆ serialize()

void game::serialize ( std::ostream &  fout)

Saving and loading functions.

Definition at line 69 of file savegame.cpp.

70{
71 /*
72 * Format version 12: Fully json, save the header. Weather and memorial exist elsewhere.
73 * To prevent (or encourage) confusion, there is no version 8. (cata 0.8 uses v7)
74 */
75 // Header
76 fout << "# version " << savegame_version << std::endl;
77
78 JsonOut json( fout, true ); // pretty-print
79
80 json.start_object();
81 // basic game state information.
82 json.member( "turn", calendar::turn );
84 json.member( "calendar_start", calendar_config._start_of_cataclysm );
85 json.member( "game_start", calendar_config._start_of_game );
86 json.member( "initial_season", static_cast<int>( calendar_config._initial_season ) );
87 json.member( "auto_travel_mode", auto_travel_mode );
88 json.member( "run_mode", static_cast<int>( safe_mode ) );
89 json.member( "mostseen", mostseen );
90 // current map coordinates
91 tripoint pos_sm = m.get_abs_sub();
92 const point pos_om = sm_to_om_remain( pos_sm.x, pos_sm.y );
93 json.member( "levx", pos_sm.x );
94 json.member( "levy", pos_sm.y );
95 json.member( "levz", pos_sm.z );
96 json.member( "om_x", pos_om.x );
97 json.member( "om_y", pos_om.y );
98
99 json.member( "grscent", scent.serialize() );
100 json.member( "typescent", scent.serialize( true ) );
101
102 // Then each monster
103 json.member( "active_monsters", *critter_tracker );
104 json.member( "stair_monsters", coming_to_stairs );
105
106 // save stats.
107 json.member( "kill_tracker", *kill_tracker_ptr );
108 json.member( "stats_tracker", *stats_tracker_ptr );
109 json.member( "achievements_tracker", *achievements_tracker_ptr );
110
111 json.member( "token_provider", *token_provider_ptr );
112
113 json.member( "player", u );
114 Messages::serialize( json );
115
116 json.end_object();
117}
Definition: json.h:575
A class that keeps time data other than current time.
Definition: calendar.h:530
season_type _initial_season
Definition: calendar.h:534
time_point _start_of_game
Definition: calendar.h:533
time_point _start_of_cataclysm
Definition: calendar.h:532
pimpl< drop_token_provider > token_provider_ptr
Definition: game.h:974
std::string serialize(bool is_type=false) const
Definition: savegame.cpp:119
point sm_to_om_remain(int &x, int &y)
void serialize(JsonOut &json)
Definition: messages.cpp:321
calendar_config config
const int savegame_version
Definition: savegame.cpp:57

References calendar_config::_initial_season, calendar_config::_start_of_cataclysm, calendar_config::_start_of_game, achievements_tracker_ptr, auto_travel_mode, coming_to_stairs, calendar::config, critter_tracker, JsonOut::end_object(), map::get_abs_sub(), kill_tracker_ptr, m, JsonOut::member(), mostseen, safe_mode, savegame_version, scent, scent_map::serialize(), Messages::serialize(), sm_to_om_remain(), JsonOut::start_object(), stats_tracker_ptr, token_provider_ptr, calendar::turn, u, point::x, tripoint::x, point::y, tripoint::y, and tripoint::z.

Referenced by save_player_data().

◆ serialize_master()

void game::serialize_master ( std::ostream &  fout)
private

Definition at line 1243 of file savegame.cpp.

1244{
1245 fout << "# version " << savegame_version << std::endl;
1246 try {
1247 JsonOut json( fout, true ); // pretty-print
1248 json.start_object();
1249
1250 json.member( "next_mission_id", next_mission_id );
1251 json.member( "next_npc_id", next_npc_id );
1252
1253 json.member( "active_missions" );
1254 mission::serialize_all( json );
1255
1256 json.member( "factions", *faction_manager_ptr );
1257 json.member( "seed", seed );
1258
1259 json.member( "weather" );
1260 json.start_object();
1261 json.member( "lightning", get_weather().lightning_active );
1262 json.end_object();
1263
1264 json.end_object();
1265 } catch( const JsonError &e ) {
1266 debugmsg( "error saving to %s: %s", SAVE_MASTER, e.c_str() );
1267 }
1268}
Definition: json.h:51
const char * c_str() const noexcept
Definition: json.h:54
static void serialize_all(JsonOut &json)
Definition: savegame.cpp:1234

References JsonError::c_str(), debugmsg, JsonOut::end_object(), faction_manager_ptr, get_weather, JsonOut::member(), next_mission_id, next_npc_id, SAVE_MASTER(), savegame_version, seed, mission::serialize_all(), and JsonOut::start_object().

Referenced by save_factions_missions_npcs().

◆ set_critter_died()

void game::set_critter_died ( )

If invoked, dead will be cleaned this turn.

Definition at line 1788 of file game.cpp.

1789{
1790 critter_died = true;
1791}

References critter_died.

◆ set_driving_view_offset()

void game::set_driving_view_offset ( point  p)

Definition at line 1598 of file game.cpp.

1599{
1600 // remove the previous driving offset,
1601 // store the new offset and apply the new offset.
1608}

References driving_view_offset, u, player::view_offset, point::x, tripoint::x, point::y, and tripoint::y.

Referenced by calc_driving_offset(), and cleanup_at_end().

◆ set_npcs_dirty()

void game::set_npcs_dirty ( )

If invoked, NPCs will be reloaded before next turn.

Definition at line 1783 of file game.cpp.

1784{
1785 npcs_dirty = true;
1786}

References npcs_dirty.

◆ set_safe_mode()

void game::set_safe_mode ( safe_mode_type  mode)

Definition at line 8651 of file game.cpp.

8652{
8653 safe_mode = mode;
8655}

References safe_mode, and safe_mode_warning_logged.

Referenced by handle_action(), and mon_info_update().

◆ set_zoom()

void game::set_zoom ( int  level)

Definition at line 7106 of file game.cpp.

7107{
7108#if defined(TILES)
7109 if( tileset_zoom != level ) {
7110 tileset_zoom = level;
7111 rescale_tileset( tileset_zoom );
7112 }
7113#else
7114 static_cast<void>( level );
7115#endif // TILES
7116}

References tileset_zoom.

Referenced by look_around().

◆ setremoteveh()

void game::setremoteveh ( vehicle veh)

Sets the current remotely controlled vehicle.

Definition at line 2273 of file game.cpp.

2274{
2276 remoteveh_cache = veh;
2277 if( veh != nullptr && !u.has_active_bionic( bio_remote ) &&
2279 debugmsg( "Tried to set remote vehicle without bio_remote or remotevehcontrol" );
2280 veh = nullptr;
2281 }
2282
2283 if( veh == nullptr ) {
2284 u.remove_value( "remote_controlling_vehicle" );
2285 return;
2286 }
2287
2288 std::stringstream remote_veh_string;
2289 const tripoint vehpos = veh->global_pos3();
2290 remote_veh_string << vehpos.x << ' ' << vehpos.y << ' ' << vehpos.z;
2291 u.set_value( "remote_controlling_vehicle", remote_veh_string.str() );
2292}
void remove_value(const std::string &key)
Definition: creature.cpp:1377

References bio_remote, debugmsg, vehicle::global_pos3(), Character::has_active_bionic(), Character::has_active_item(), itype_remotevehcontrol, remoteveh_cache, remoteveh_cache_time, Creature::remove_value(), Creature::set_value(), calendar::turn, u, tripoint::x, tripoint::y, and tripoint::z.

◆ setup()

void game::setup ( )

Definition at line 479 of file game.cpp.

480{
481 loading_ui ui( true );
482
484
485 if( get_option<bool>( "ELEVATED_BRIDGES" ) && !get_option<bool>( "ZLEVELS" ) ) {
486 debugmsg( "\"Elevated bridges\" mod requires z-levels to be ENABLED to work properly!" );
487 }
488
489 m = map( get_option<bool>( "ZLEVELS" ) );
490
492 next_mission_id = 1;
493 new_game = true;
494 uquit = QUIT_NO; // We haven't quit the game
495 bVMonsterLookFire = true;
496
497 // invalidate calendar caches in case we were previously playing
498 // a different world
499 calendar::set_eternal_season( ::get_option<bool>( "ETERNAL_SEASON" ) );
500 calendar::set_season_length( ::get_option<int>( "SEASON_LENGTH" ) );
501
504
505 turnssincelastmon = 0; //Auto safe mode init
506
509 coming_to_stairs.clear();
510 active_npc.clear();
511 faction_manager_ptr->clear();
516
517 SCT.vSCT.clear(); //Delete pending messages
518
519 stats().clear();
520 // reset kill counts
523 // reset follower list
524 follower_ids.clear();
525 scent.reset();
526
528 remoteveh_cache = nullptr;
529
530 token_provider_ptr->clear();
531 // back to menu for save loading, new game etc
532}
void clear_zombies()
Redirects to the creature_tracker clear() function.
Definition: game.cpp:4739
static void clear_all()
Remove all active missions, used to cleanup on exit and before reloading a new game.
Definition: mission.cpp:127
void reset()
Definition: scent_map.cpp:51
static const string_id< weather_type > & NULL_ID()
Returns a null id whose string_id<T>::is_null() must always return true.
void clear_messages()
Definition: messages.cpp:351
void load_world_modfiles(loading_ui &ui, const std::string &artifacts_file)
Load & finalize modlist needed for the current world.
Definition: init.cpp:933
void reset_sounds()
Definition: sounds.cpp:566

References achievements_tracker_ptr, active_npc, calendar::before_time_starts, bVMonsterLookFire, character_id, explosion_handler::explosion_queue::clear(), kill_tracker::clear(), stats_tracker::clear(), mission::clear_all(), Messages::clear_messages(), clear_zombies(), coming_to_stairs, debugmsg, faction_manager_ptr, follower_ids, explosion_handler::get_explosion_queue(), get_kill_tracker(), get_weather, get_world_base_save_path(), init::load_world_modfiles(), m, new_game, next_mission_id, next_npc_id, weather_manager::nextweather, string_id< weather_type >::NULL_ID(), QUIT_NO, remoteveh_cache, remoteveh_cache_time, scent_map::reset(), sounds::reset_sounds(), SAVE_ARTIFACTS(), scent, SCT, calendar::set_eternal_season(), calendar::set_season_length(), stats(), timed_events, token_provider_ptr, turnssincelastmon, uquit, scrollingcombattext::vSCT, and weather_manager::weather_id.

Referenced by butcher_submenu(), and quickload().

◆ shared_from()

template<typename T >
template shared_ptr_fast< npc > game::shared_from< npc > ( const T &  critter)

Returns a shared pointer to the given critter (which can be of any of the subclasses of Creature).

The function may return an empty pointer if the given critter is not stored anywhere (e.g. it was allocated on the stack, not stored in the critter_tracker nor in active_npc nor is it u).

Definition at line 4592 of file game.cpp.

4593{
4594 if( static_cast<const Creature *>( &critter ) == static_cast<const Creature *>( &u ) ) {
4595 // u is not stored in a shared_ptr, but it won't go out of scope anyway
4596 return std::dynamic_pointer_cast<T>( u_shared_ptr );
4597 }
4598 if( critter.is_monster() ) {
4599 if( const shared_ptr_fast<monster> mon_ptr = critter_tracker->find( critter.pos() ) ) {
4600 if( static_cast<const Creature *>( mon_ptr.get() ) == static_cast<const Creature *>( &critter ) ) {
4601 return std::dynamic_pointer_cast<T>( mon_ptr );
4602 }
4603 }
4604 }
4605 if( critter.is_npc() ) {
4606 for( auto &cur_npc : active_npc ) {
4607 if( static_cast<const Creature *>( cur_npc.get() ) == static_cast<const Creature *>( &critter ) ) {
4608 return std::dynamic_pointer_cast<T>( cur_npc );
4609 }
4610 }
4611 }
4612 return nullptr;
4613}

References active_npc, critter_tracker, u, and u_shared_ptr.

Referenced by list_monsters(), mon_info_update(), and validate_mounted_npcs().

◆ shift_destination_preview()

void game::shift_destination_preview ( point  delta)

Definition at line 12074 of file game.cpp.

12075{
12076 for( tripoint &p : destination_preview ) {
12077 p += delta;
12078 }
12079}

References destination_preview.

◆ shift_monsters()

void game::shift_monsters ( const tripoint shift)
private

Shift all active monsters, the shift vector is the number of shifted submaps.

Monsters that are outside of the reality bubble after shifting are despawned. Note on z-levels: this works with vertical shifts, but currently all monsters are despawned upon a vertical shift.

Definition at line 11063 of file game.cpp.

11064{
11065 // If either shift argument is non-zero, we're shifting.
11066 if( shift == tripoint_zero ) {
11067 return;
11068 }
11069 for( monster &critter : all_monsters() ) {
11070 if( shift.xy() != point_zero ) {
11071 critter.shift( shift.xy() );
11072 }
11073
11074 if( m.inbounds( critter.pos() ) && ( shift.z == 0 || m.has_zlevels() ) ) {
11075 // We're inbounds, so don't despawn after all.
11076 // No need to shift Z-coordinates, they are absolute
11077 continue;
11078 }
11079 // Either a vertical shift or the critter is now outside of the reality bubble,
11080 // anyway: it must be saved and removed.
11081 despawn_monster( critter );
11082 }
11083 // The order in which zombies are shifted may cause zombies to briefly exist on
11084 // the same square. This messes up the mon_at cache, so we need to rebuild it.
11085 critter_tracker->rebuild_cache();
11086}

References all_monsters(), critter_tracker, despawn_monster(), map::has_zlevels(), map::inbounds(), m, point_zero, tripoint_zero, tripoint::xy(), and tripoint::z.

Referenced by update_map(), vertical_move(), and vertical_shift().

◆ slip_down()

bool game::slip_down ( )

Checks if player is able to successfully climb to/from some terrain and not slip down.

Returns
whether player has slipped down
Dexterity decreases chances of slipping while climbing

Definition at line 12081 of file game.cpp.

12082{
12083 ///\EFFECT_DEX decreases chances of slipping while climbing
12084 int climb = u.dex_cur;
12085 if( u.has_trait( trait_BADKNEES ) ) {
12086 climb = climb / 2;
12087 }
12088 if( one_in( climb ) ) {
12089 add_msg( m_bad, _( "You slip while climbing and fall down again." ) );
12090 if( climb <= 1 ) {
12091 add_msg( m_bad, _( "Climbing is impossible in your current state." ) );
12092 }
12093 return true;
12094 }
12095 return false;
12096}
static const trait_id trait_BADKNEES("BADKNEES")

References _, add_msg(), Character::dex_cur, Character::has_trait(), m_bad, one_in(), trait_BADKNEES, and u.

◆ spawn_hallucination()

bool game::spawn_hallucination ( const tripoint p)

Spawns a hallucination at a determined position.

Attempts to spawn a hallucination at given location.

Returns false if the hallucination couldn't be spawned for whatever reason, such as a monster already in the target square.

Returns
Whether or not a hallucination was successfully spawned.

Definition at line 4750 of file game.cpp.

4751{
4752 if( one_in( 100 ) ) {
4753 shared_ptr_fast<npc> tmp = make_shared_fast<npc>();
4754 tmp->randomize( NC_HALLU );
4755 tmp->spawn_at_precise( { get_levx(), get_levy() }, p );
4756 if( !critter_at( p, true ) ) {
4758 load_npcs();
4759 return true;
4760 } else {
4761 return false;
4762 }
4763 }
4764
4766 const shared_ptr_fast<monster> phantasm = make_shared_fast<monster>( mt );
4767 phantasm->hallucination = true;
4768 phantasm->spawn( p );
4769
4770 //Don't attempt to place phantasms inside of other creatures
4771 if( !critter_at( phantasm->pos(), true ) ) {
4772 return critter_tracker->add( phantasm );
4773 } else {
4774 return false;
4775 }
4776}
mtype_id get_valid_hallucination() const
static MonsterGenerator & generator()
npc_class_id NC_HALLU("NC_HALLU")

References critter_at(), critter_tracker, MonsterGenerator::generator(), get_levx(), get_levy(), MonsterGenerator::get_valid_hallucination(), overmapbuffer::insert_npc(), load_npcs(), NC_HALLU, one_in(), and overmap_buffer.

◆ spell_events_subscriber()

spell_events & game::spell_events_subscriber ( )

Definition at line 2733 of file game.cpp.

2734{
2735 return *spell_events_ptr;
2736}

References spell_events_ptr.

◆ start_calendar()

void game::start_calendar ( )

Definition at line 11641 of file game.cpp.

11642{
11643 const bool scen_season = scen->has_flag( "SPR_START" ) || scen->has_flag( "SUM_START" ) ||
11644 scen->has_flag( "AUT_START" ) || scen->has_flag( "WIN_START" ) ||
11645 scen->has_flag( "SUM_ADV_START" );
11646
11648 if( scen_season ) {
11649 // Configured starting date overridden by scenario, calendar_config.start is left as Spring 1
11651 get_option<int>( "INITIAL_TIME" );
11652 calendar_config._start_of_game = calendar::turn_zero + 1_hours * get_option<int>( "INITIAL_TIME" );
11653 if( scen->has_flag( "SPR_START" ) ) {
11655 } else if( scen->has_flag( "SUM_START" ) ) {
11658 } else if( scen->has_flag( "AUT_START" ) ) {
11661 } else if( scen->has_flag( "WIN_START" ) ) {
11664 } else if( scen->has_flag( "SUM_ADV_START" ) ) {
11667 } else {
11668 debugmsg( "The Unicorn" );
11669 }
11670 } else {
11671 // No scenario, so use the starting date+time configured in world options
11672 int initial_days = get_option<int>( "INITIAL_DAY" );
11673 if( initial_days == -1 ) {
11674 // 0 - 363 for a 91 day season
11675 initial_days = rng( 0, get_option<int>( "SEASON_LENGTH" ) * 4 - 1 );
11676 }
11678
11679 // Determine the season based off how long the seasons are set to be
11680 // First take the number of season elapsed up to the starting date, then mod by 4 to get the season of the current year
11681 const int season_number = ( initial_days / get_option<int>( "SEASON_LENGTH" ) ) % 4;
11682 if( season_number == 0 ) {
11684 } else if( season_number == 1 ) {
11686 } else if( season_number == 2 ) {
11688 } else {
11690 }
11691
11693 + 1_hours * get_option<int>( "INITIAL_TIME" )
11694 + 1_days * get_option<int>( "SPAWN_DELAY" );
11695 }
11696
11698}
@ WINTER
Definition: calendar.h:21
@ AUTUMN
Definition: calendar.h:20
@ SUMMER
Definition: calendar.h:19
@ SPRING
Definition: calendar.h:18
time_duration season_length() const
Definition: calendar.h:569
const scenario * scen
Definition: game.h:981
bool has_flag(const std::string &flag) const
Such as a seasonal start, fiery start, surrounded start, etc.
Definition: scenario.cpp:438

References calendar_config::_initial_season, calendar_config::_start_of_cataclysm, calendar_config::_start_of_game, AUTUMN, calendar::config, debugmsg, scenario::has_flag(), rng(), scen, calendar_config::season_length(), SPRING, SUMMER, calendar::turn, calendar::turn_zero, and WINTER.

Referenced by start_game().

◆ start_game()

bool game::start_game ( )
private

Definition at line 558 of file game.cpp.

559{
560 if( !gamemode ) {
561 gamemode = std::make_unique<special_game>();
562 }
563
564 seed = rng_bits();
565 new_game = true;
568 safe_mode = ( get_option<bool>( "SAFEMODE" ) ? SAFE_MODE_ON : SAFE_MODE_OFF );
569 mostseen = 0; // ...and mostseen is 0, we haven't seen any monsters yet.
572
574
577 popup.message( "%s", _( "Please wait as we build your world" ) );
580
581 load_master();
582 u.setID( assign_npc_id() ); // should be as soon as possible, but *after* load_master
583
587 do {
588 omtstart = start_loc.find_player_initial_location();
589 if( omtstart == overmap::invalid_tripoint ) {
590 if( query_yn(
591 _( "Try again?\n\nIt may require several attempts until the game finds a valid starting location." ) ) ) {
594 } else {
595 return false;
596 }
597 }
598 } while( omtstart == overmap::invalid_tripoint );
599
600 start_loc.prepare_map( omtstart );
601
602 // Place vehicles spawned by scenario or profession, has to be placed very early to avoid bugs.
603 if( u.starting_vehicle &&
604 !place_vehicle_nearby( u.starting_vehicle, omtstart.xy(), 0, 30,
605 std::vector<std::string> {} ) ) {
606 debugmsg( "could not place starting vehicle" );
607 }
608
609 if( scen->has_map_extra() ) {
610 // Map extras can add monster spawn points and similar and should be done before the main
611 // map is loaded.
612 start_loc.add_map_extra( omtstart, scen->get_map_extra() );
613 }
614
615 // TODO: fix point types
616 tripoint lev = project_to<coords::sm>( omtstart ).raw();
617 // The player is centered in the map, but lev[xyz] refers to the top left point of the map
618 lev.x -= HALF_MAPSIZE;
619 lev.y -= HALF_MAPSIZE;
620 load_map( lev, /*pump_events=*/true );
621
624 // Do this after the map cache has been built!
625 start_loc.place_player( u );
626 // ...but then rebuild it, because we want visibility cache to avoid spawning monsters in sight
629 // Start the overmap with out immediate neighborhood visible, this needs to be after place_player
631 get_option<int>( "DISTANCE_INITIAL_VISIBILITY" ), 0 );
632
633 u.moves = 0;
634 if( u.has_trait( trait_PROF_FERAL ) ) {
636 }
637 u.process_turn(); // process_turn adds the initial move points
640 u.next_climate_control_check = calendar::before_time_starts; // Force recheck at startup
642
643 //Reset character safe mode/pickup rules
648
649 //Put some NPCs in there!
650 if( get_option<std::string>( "STARTING_NPC" ) == "always" ||
651 ( get_option<std::string>( "STARTING_NPC" ) == "scenario" &&
652 !g->scen->has_flag( "LONE_START" ) ) ) {
654 }
655 //Load NPCs. Set nearby npcs to active.
656 load_npcs();
657 // Spawn the monsters
658 const bool spawn_near =
659 get_option<bool>( "BLACK_ROAD" ) || g->scen->has_flag( "SUR_START" );
660 // Surrounded start ones
661 if( spawn_near ) {
662 start_loc.surround_with_monsters( omtstart, mongroup_id( "GROUP_ZOMBIE" ), 70 );
663 }
664
665 m.spawn_monsters( !spawn_near ); // Static monsters
666
667 // Make sure that no monsters are near the player
668 // This can happen in lab starts
669 if( !spawn_near ) {
670 for( monster &critter : all_monsters() ) {
671 if( rl_dist( critter.pos(), u.pos() ) <= 5 ||
672 m.clear_path( critter.pos(), u.pos(), 40, 1, 100 ) ) {
673 remove_zombie( critter );
674 }
675 }
676 }
677
678 //Create mutation_category_level
680 //Calculate mutation drench protection stats
683 if( scen->has_flag( "FIRE_START" ) ) {
684 start_loc.burn( omtstart, 3, 3 );
685 }
686 if( scen->has_flag( "INFECTED" ) ) {
688 }
689 if( scen->has_flag( "BAD_DAY" ) ) {
690 u.add_effect( effect_flu, 1000_minutes );
691 u.add_effect( effect_drunk, 270_minutes );
692 u.add_morale( MORALE_FEELING_BAD, -100, -100, 50_minutes, 50_minutes );
693 }
694 if( scen->has_flag( "HELI_CRASH" ) ) {
695 start_loc.handle_heli_crash( u );
696 bool success = false;
697 for( auto v : m.get_vehicles() ) {
698 std::string name = v.v->type.str();
699 std::string search = std::string( "helicopter" );
700 if( name.find( search ) != std::string::npos ) {
701 for( const vpart_reference &vp : v.v->get_any_parts( VPFLAG_CONTROLS ) ) {
702 const tripoint pos = vp.pos();
703 u.setpos( pos );
704
705 // Delete the items that would have spawned here from a "corpse"
706 for( auto sp : v.v->parts_at_relative( vp.mount(), true ) ) {
707 vehicle_stack here = v.v->get_items( sp );
708
709 for( auto iter = here.begin(); iter != here.end(); ) {
710 iter = here.erase( iter );
711 }
712 }
713
714 auto mons = critter_tracker->find( pos );
715 if( mons != nullptr ) {
716 critter_tracker->remove( *mons );
717 }
718
719 success = true;
720 break;
721 }
722 if( success ) {
723 v.v->name = "Bird Wreckage";
724 break;
725 }
726 }
727 }
728 }
729 if( scen->has_flag( "BORDERED" ) ) {
730 overmap &starting_om = get_cur_om();
731 for( int z = -OVERMAP_DEPTH; z <= OVERMAP_HEIGHT; z++ ) {
732 starting_om.place_special_forced( overmap_special_id( "world" ), { 0, 0, z },
734 }
735
736 }
737 for( auto &e : u.inv_dump() ) {
738 e->set_owner( g->u );
739 }
740 // Now that we're done handling coordinates, ensure the player's submap is in the center of the map
741 update_map( u );
742 // Profession pets
743 for( const mtype_id &elem : u.starting_pets ) {
744 if( monster *const mon = place_critter_around( elem, u.pos(), 5 ) ) {
745 mon->friendly = -1;
746 mon->add_effect( effect_pet, 1_turns, num_bp );
747 } else {
748 add_msg( m_debug, "cannot place starting pet, no space!" );
749 }
750 }
751 // Assign all of this scenario's missions to the player.
752 for( const mission_type_id &m : scen->missions() ) {
753 const auto mission = mission::reserve_new( m, character_id() );
754 mission->assign( u );
755 }
756 g->events().send<event_type::game_start>( u.getID() );
757 for( Skill &elem : Skill::skills ) {
758 int level = u.get_skill_level_object( elem.ident() ).level();
759 if( level > 0 ) {
760 g->events().send<event_type::gains_skill_level>( u.getID(), elem.ident(), level );
761 }
762 }
763 return true;
764}
body_part random_body_part(bool main_parts_only)
Returns a random body_part token.
Definition: bodypart.cpp:366
bool last_climate_control_ret
Definition: character.h:2294
SkillLevel & get_skill_level_object(const skill_id &ident)
Definition: character.cpp:3345
void drench_mut_calc()
Recalculates mutation drench protection for all bodyparts (ignored/good/neutral stats)
Definition: character.cpp:7823
void set_stamina(int new_stamina)
Definition: character.cpp:7109
time_point next_climate_control_check
Definition: character.h:2293
int get_stamina_max() const
Definition: character.cpp:7098
void set_highest_cat_level()
Recalculates mutation_category_level[] values for the player.
Definition: character.cpp:7800
void default_initialize()
Perform default initialization.
Definition: auto_note.cpp:101
void start_calendar()
Definition: game.cpp:11641
void create_starting_npcs()
Definition: game.cpp:887
overmap & get_cur_om() const
The overmap which contains the center submap of the reality bubble.
Definition: game.cpp:11941
vehicle * place_vehicle_nearby(const vproto_id &id, const point_abs_omt &origin, int min_distance, int max_distance, const std::vector< std::string > &omt_search_types={})
Definition: game.cpp:766
bool clear_path(const tripoint &f, const tripoint &t, int range, int cost_min, int cost_max) const
Check whether there's a direct line of sight between F and T with the additional movecost restraints.
Definition: map.cpp:6535
static mission * reserve_new(const mission_type_id &type, const character_id &npc_id)
Create a new mission of the given type and assign it to the given npc.
Definition: mission.cpp:64
void assign(avatar &u)
Assigns the mission to the player.
Definition: mission.cpp:210
void place_special_forced(const overmap_special_id &special_id, const tripoint_om_omt &p, om_direction::type dir)
Definition: overmap.cpp:2164
bool reveal(const point_abs_omt &center, int radius, int z)
Mark a square area around center on Z-level z as seen.
bool random_start_location
Definition: player.h:238
vproto_id starting_vehicle
Definition: player.h:250
std::vector< mtype_id > starting_pets
Definition: player.h:251
start_location_id start_location
Definition: player.h:239
void clear_character_rules()
bool has_map_extra() const
Definition: scenario.cpp:453
const std::string & get_map_extra() const
Definition: scenario.cpp:457
const std::vector< mission_type_id > & missions() const
Definition: scenario.cpp:461
start_location_id random_start_location() const
Definition: scenario.cpp:232
void burn(const tripoint_abs_omt &omtstart, size_t count, int rad) const
Burn random terrain / furniture with FLAMMABLE or FLAMMABLE_ASH tag.
void surround_with_monsters(const tripoint_abs_omt &omtstart, const mongroup_id &type, float expected_points) const
Adds surround start monsters.
void prepare_map(const tripoint_abs_omt &omtstart) const
Initialize the map at players start location using prepare_map.
void place_player(player &u) const
Place the player somewhere in the reality bubble (g->m).
void handle_heli_crash(player &u) const
tripoint_abs_omt find_player_initial_location() const
Find a suitable start location on the overmap.
void add_map_extra(const tripoint_abs_omt &omtstart, const std::string &map_extra) const
Adds a map extra, see map_extras.h and map_extras.cpp.
const T & obj() const
Returns the actual object this id refers to.
Definition: achievement.cpp:63
static const efftype_id effect_drunk("drunk")
static const efftype_id effect_infected("infected")
static const trait_id trait_PROF_FERAL("PROF_FERAL")
static const efftype_id effect_accumulated_mutagen("accumulated_mutagen")
static const efftype_id effect_flu("flu")
static const efftype_id effect_feral_killed_recently("feral_killed_recently")
void update_weather()
Definition: weather.cpp:1059
const morale_type MORALE_FEELING_BAD("morale_feeling_bad")
static bool search(const ui_adaptor &om_ui, tripoint_abs_omt &curs, const tripoint_abs_omt &orig)
unsigned int rng_bits()
Definition: rng.cpp:12
string_id< overmap_special > overmap_special_id
Definition: type_id.h:137
string_id< MonsterGroup > mongroup_id
Definition: type_id.h:108
@ VPFLAG_CONTROLS
Definition: veh_type.h:41

References _, Creature::add_effect(), start_location::add_map_extra(), Character::add_morale(), add_msg(), all_monsters(), mission::assign(), assign_npc_id(), calendar::before_time_starts, map::build_map_cache(), start_location::burn(), character_id, auto_notes::auto_note_settings::clear(), mapbuffer::clear(), overmapbuffer::clear(), auto_pickup::player_settings::clear_character_rules(), safemode::clear_character_rules(), map::clear_path(), create_starting_npcs(), critter_tracker, debugmsg, auto_notes::auto_note_settings::default_initialize(), Character::drench_mut_calc(), effect_accumulated_mutagen, effect_drunk, effect_feral_killed_recently, effect_flu, effect_infected, effect_pet, start_location::find_player_initial_location(), g, gains_skill_level, game_start, gamemode, get_auto_notes_settings(), get_auto_pickup(), get_cur_om(), get_distraction_manager(), get_levz(), scenario::get_map_extra(), get_safemode(), Character::get_skill_level_object(), Character::get_stamina_max(), map::get_vehicles(), get_weather, Character::getID(), Character::global_omt_location(), HALF_MAPSIZE, start_location::handle_heli_crash(), scenario::has_flag(), scenario::has_map_extra(), Character::has_trait(), anonymous_namespace{iexamine_elevator.cpp}::elevator::here(), init_autosave(), Character::inv_dump(), overmap::invalid_tripoint, map::invalidate_map_cache(), Character::last_climate_control_ret, distraction_manager::distraction_manager_gui::load(), safemode::load_global(), load_map(), load_master(), load_npcs(), m, m_debug, MAPBUFFER, scenario::missions(), MORALE_FEELING_BAD, mostseen, Creature::moves, om_direction::name(), new_game, Character::next_climate_control_check, weather_manager::nextweather, om_direction::north, num_bp, string_id< T >::obj(), overmap_buffer, OVERMAP_DEPTH, OVERMAP_HEIGHT, place_critter_around(), start_location::place_player(), overmap::place_special_forced(), place_vehicle_nearby(), popup(), Character::pos(), start_location::prepare_map(), Character::process_turn(), query_yn(), random_body_part(), player::random_start_location, scenario::random_start_location(), ui_manager::redraw(), refresh_display(), remove_zombie(), mission::reserve_new(), overmapbuffer::reveal(), rl_dist(), rng_bits(), safe_mode, SAFE_MODE_OFF, SAFE_MODE_ON, scen, overmap_ui::search(), seed, Character::set_highest_cat_level(), Character::set_stamina(), Character::setID(), Character::setpos(), Skill::skills, map::spawn_monsters(), start_calendar(), player::start_location, player::starting_pets, player::starting_vehicle, behavior::success, start_location::surround_with_monsters(), trait_PROF_FERAL, calendar::turn, u, update_map(), weather_manager::update_weather(), VPFLAG_CONTROLS, tripoint::x, coords::coord_point< Point, Origin, Scale >::xy(), and tripoint::y.

◆ start_hauling()

void game::start_hauling ( const tripoint pos)

Definition at line 10426 of file game.cpp.

10427{
10428 // Find target items and quantities thereof for the new activity
10429 std::vector<item_location> target_items;
10430 std::vector<int> quantities;
10431
10432 map_stack items = m.i_at( pos );
10433 for( item &it : items ) {
10434 // Liquid cannot be picked up
10435 if( it.made_of( LIQUID ) ) {
10436 continue;
10437 }
10438 target_items.emplace_back( map_cursor( pos ), &it );
10439 // Quantity of 0 means move all
10440 quantities.push_back( 0 );
10441 }
10442
10443 if( target_items.empty() ) {
10444 // Nothing to haul
10445 return;
10446 }
10447
10448 // Whether the destination is inside a vehicle (not supported)
10449 const bool to_vehicle = false;
10450 // Destination relative to the player
10451 const tripoint relative_destination{};
10452
10454 target_items,
10455 quantities,
10456 to_vehicle,
10457 relative_destination
10458 ) ) );
10459}

References Character::assign_activity(), map::i_at(), LIQUID, m, and u.

Referenced by vertical_move(), and walk_move().

◆ stats()

stats_tracker & game::stats ( )

Definition at line 2718 of file game.cpp.

2719{
2720 return *stats_tracker_ptr;
2721}

References stats_tracker_ptr.

Referenced by death_screen(), handle_action(), setup(), and win().

◆ swap_critters()

bool game::swap_critters ( Creature a,
Creature b 
)

Swaps positions of two creatures.

Definition at line 4778 of file game.cpp.

4779{
4780 if( &a == &b ) {
4781 // No need to do anything, but print a debugmsg anyway
4782 debugmsg( "Tried to swap %s with itself", a.disp_name() );
4783 return true;
4784 }
4785 if( critter_at( a.pos() ) != &a ) {
4786 debugmsg( "Tried to swap when it would cause a collision between %s and %s.",
4787 b.disp_name(), critter_at( a.pos() )->disp_name() );
4788 return false;
4789 }
4790 if( critter_at( b.pos() ) != &b ) {
4791 debugmsg( "Tried to swap when it would cause a collision between %s and %s.",
4792 a.disp_name(), critter_at( b.pos() )->disp_name() );
4793 return false;
4794 }
4795 // Simplify by "sorting" the arguments
4796 // Only the first argument can be u
4797 // If swapping player/npc with a monster, monster is second
4798 bool a_first = a.is_player() ||
4799 ( a.is_npc() && !b.is_player() );
4800 Creature &first = a_first ? a : b;
4801 Creature &second = a_first ? b : a;
4802 // Possible options:
4803 // both first and second are monsters
4804 // second is a monster, first is a player or an npc
4805 // first is a player, second is an npc
4806 // both first and second are npcs
4807 if( first.is_monster() ) {
4808 monster *m1 = dynamic_cast< monster * >( &first );
4809 monster *m2 = dynamic_cast< monster * >( &second );
4810 if( m1 == nullptr || m2 == nullptr || m1 == m2 ) {
4811 debugmsg( "Couldn't swap two monsters" );
4812 return false;
4813 }
4814
4815 critter_tracker->swap_positions( *m1, *m2 );
4816 return true;
4817 }
4818
4819 player *u_or_npc = dynamic_cast< player * >( &first );
4820 player *other_npc = dynamic_cast< player * >( &second );
4821
4822 if( u_or_npc->in_vehicle ) {
4823 m.unboard_vehicle( u_or_npc->pos() );
4824 }
4825
4826 if( other_npc && other_npc->in_vehicle ) {
4827 m.unboard_vehicle( other_npc->pos() );
4828 }
4829
4830 tripoint temp = second.pos();
4831 second.setpos( first.pos() );
4832
4833 if( first.is_player() ) {
4834 walk_move( temp );
4835 } else {
4836 first.setpos( temp );
4837 if( m.veh_at( u_or_npc->pos() ).part_with_feature( VPFLAG_BOARDABLE, true ) ) {
4838 m.board_vehicle( u_or_npc->pos(), u_or_npc );
4839 }
4840 }
4841
4842 if( other_npc && m.veh_at( other_npc->pos() ).part_with_feature( VPFLAG_BOARDABLE, true ) ) {
4843 m.board_vehicle( other_npc->pos(), other_npc );
4844 }
4845 return true;
4846}
virtual bool is_monster() const
Definition: creature.h:101
virtual bool is_player() const
Definition: creature.h:92
virtual void setpos(const tripoint &pos)=0
bool walk_move(const tripoint &dest, bool via_ramp=false)
Definition: game.cpp:8796
constexpr double a
Definition: magic.cpp:1030
constexpr double b
Definition: magic.cpp:1031
@ VPFLAG_BOARDABLE
Definition: veh_type.h:39

References a, b, map::board_vehicle(), critter_at(), critter_tracker, debugmsg, Character::in_vehicle, Creature::is_monster(), Creature::is_player(), m, optional_vpart_position::part_with_feature(), Creature::pos(), Character::pos(), second, Creature::setpos(), map::unboard_vehicle(), map::veh_at(), VPFLAG_BOARDABLE, and walk_move().

Referenced by npc_menu().

◆ take_screenshot() [1/2]

bool game::take_screenshot ( ) const

Saves a screenshot of the current viewport, as a PNG file.

Filesystem location is derived from the current world and character.

Note
: Only works for SDL/TILES (otherwise the function returns false). A window (more precisely, a viewport) must already exist and the SDL renderer must be valid.
Returns
true if the screenshot generation was successful, false otherwise.

Definition at line 7175 of file game.cpp.

7176{
7177 popup( _( "This binary was not compiled with tiles support." ) );
7178 return false;
7179}

References _, and popup().

Referenced by do_turn().

◆ take_screenshot() [2/2]

bool game::take_screenshot ( const std::string &  file_path) const

Saves a screenshot of the current viewport, as a PNG file, to the given location.

Parameters
file_pathA full path to the file where the screenshot should be saved.
Note
: Only works for SDL/TILES (otherwise the function returns false). A window (more precisely, a viewport) must already exist and the SDL renderer must be valid.
Returns
true if the screenshot generation was successful, false otherwise.

Definition at line 7169 of file game.cpp.

7170{
7171 popup( _( "This binary was not compiled with tiles support." ) );
7172 return false;
7173}

References _, and popup().

◆ temp_exit_fullscreen()

void game::temp_exit_fullscreen ( )

Definition at line 457 of file game.cpp.

458{
459 if( fullscreen ) {
460 was_fullscreen = true;
462 } else {
463 was_fullscreen = false;
464 }
465}

References fullscreen, toggle_fullscreen(), and was_fullscreen.

Referenced by list_items_monsters(), and look_around().

◆ toggle_debug_hour_timer()

void game::toggle_debug_hour_timer ( )

Definition at line 11248 of file game.cpp.

11249{
11251}

References game::debug_hour_timer::toggle().

Referenced by handle_action(), and look_around().

◆ toggle_fullscreen()

void game::toggle_fullscreen ( )

Definition at line 410 of file game.cpp.

411{
412#if !defined(TILES)
415#else
416 toggle_fullscreen_window();
417#endif
418}

References fullscreen, and mark_main_ui_adaptor_resize().

Referenced by handle_action(), reenter_fullscreen(), and temp_exit_fullscreen().

◆ toggle_gate()

void game::toggle_gate ( const tripoint p)

Definition at line 5147 of file game.cpp.

5148{
5149 gates::toggle_gate( p, u );
5150}
void toggle_gate(const tripoint &pos, player &p)
opens/closes the gate via player's activity
Definition: gates.cpp:237

References gates::toggle_gate(), and u.

◆ toggle_pixel_minimap()

void game::toggle_pixel_minimap ( )

Definition at line 420 of file game.cpp.

421{
422#if defined(TILES)
424 clear_window_area( w_pixel_minimap );
425 }
428#endif // TILES
429}

References mark_main_ui_adaptor_resize(), pixel_minimap_option, and w_pixel_minimap.

Referenced by handle_action(), and look_around().

◆ try_get_left_click_action()

bool game::try_get_left_click_action ( action_id act,
const tripoint mouse_target 
)
private

Definition at line 2294 of file game.cpp.

2295{
2296 bool new_destination = true;
2297 if( !destination_preview.empty() ) {
2298 auto &final_destination = destination_preview.back();
2299 if( final_destination.x == mouse_target.x && final_destination.y == mouse_target.y ) {
2300 // Second click
2301 new_destination = false;
2303 destination_preview.clear();
2305 if( act == ACTION_NULL ) {
2306 // Something went wrong
2308 return false;
2309 }
2310 }
2311 }
2312
2313 if( new_destination ) {
2315 u.get_path_avoid() );
2316 return false;
2317 }
2318
2319 return true;
2320}

References act, ACTION_NULL, Character::clear_destination(), destination_preview, Character::get_next_auto_move_direction(), Character::get_path_avoid(), Character::get_pathfinding_settings(), m, Character::pos(), map::route(), Character::set_destination(), u, tripoint::x, and tripoint::y.

Referenced by handle_action().

◆ try_get_right_click_action()

bool game::try_get_right_click_action ( action_id act,
const tripoint mouse_target 
)
private

Definition at line 2322 of file game.cpp.

2323{
2324 const bool cleared_destination = !destination_preview.empty();
2326 destination_preview.clear();
2327
2328 if( cleared_destination ) {
2329 // Produce no-op if auto-move had just been cleared on this action
2330 // e.g. from a previous single left mouse click. This has the effect
2331 // of right-click canceling an auto-move before it is initiated.
2332 return false;
2333 }
2334
2335 const bool is_adjacent = square_dist( mouse_target.xy(), point( u.posx(), u.posy() ) ) <= 1;
2336 const bool is_self = square_dist( mouse_target.xy(), point( u.posx(), u.posy() ) ) <= 0;
2337 if( const monster *const mon = critter_at<monster>( mouse_target ) ) {
2338 if( !u.sees( *mon ) ) {
2339 add_msg( _( "Nothing relevant here." ) );
2340 return false;
2341 }
2342
2343 if( !u.primary_weapon().is_gun() ) {
2344 add_msg( m_info, _( "You are not wielding a ranged weapon." ) );
2345 return false;
2346 }
2347
2348 // TODO: Add weapon range check. This requires weapon to be reloaded.
2349
2350 act = ACTION_FIRE;
2351 } else if( is_adjacent &&
2352 m.close_door( tripoint( mouse_target.xy(), u.posz() ), !m.is_outside( u.pos() ),
2353 true ) ) {
2354 act = ACTION_CLOSE;
2355 } else if( is_self ) {
2357 } else if( is_adjacent ) {
2359 } else {
2360 add_msg( _( "Nothing relevant here." ) );
2361 return false;
2362 }
2363
2364 return true;
2365}
bool close_door(const tripoint &p, bool inside, bool check_only)
Definition: map.cpp:4094
static bool is_adjacent(const monster &z, const Creature &target)

References _, act, ACTION_CLOSE, ACTION_EXAMINE, ACTION_FIRE, ACTION_PICKUP, add_msg(), Character::clear_destination(), map::close_door(), destination_preview, is_adjacent(), item::is_gun(), map::is_outside(), m, m_info, Character::pos(), Character::posx(), Character::posy(), Character::posz(), Character::primary_weapon(), Character::sees(), square_dist(), u, and tripoint::xy().

Referenced by handle_action().

◆ unload_npcs()

void game::unload_npcs ( )
private

Unloads all NPCs.

If you call this you must later call load_npcs, lest caches get rather confused. The tests used to call this a lot when they shouldn't. It is now private to reduce the chance of similar problems in the future.

Definition at line 870 of file game.cpp.

871{
872 for( const auto &npc : active_npc ) {
873 npc->on_unload();
874 }
875
876 active_npc.clear();
877}
void on_unload()
Do some cleanup and caching as npc is being unloaded from map.
Definition: npc.cpp:2667

References active_npc, and npc::on_unload().

Referenced by place_player_overmap(), and reload_npcs().

◆ unserialize()

void game::unserialize ( std::istream &  fin)

Definition at line 167 of file savegame.cpp.

168{
169 chkversion( fin );
170 int tmpturn = 0;
171 int tmpcalstart = 0;
172 int tmprun = 0;
173 tripoint lev;
174 point com;
175 JsonIn jsin( fin );
176 try {
177 JsonObject data = jsin.get_object();
178
179 data.read( "turn", tmpturn );
180 data.read( "calendar_start", tmpcalstart );
182 calendar_config._initial_season = static_cast<season_type>( data.get_int( "initial_season",
183 static_cast<int>( SPRING ) ) );
184 // 0.E stable
185 if( savegame_loading_version < 26 ) {
186 tmpturn *= 6;
187 tmpcalstart *= 6;
188 }
191 tmpcalstart );
192
193 if( !data.read( "game_start", calendar_config._start_of_game ) ) {
195 }
196
197 data.read( "auto_travel_mode", auto_travel_mode );
198 data.read( "run_mode", tmprun );
199 data.read( "mostseen", mostseen );
200 data.read( "levx", lev.x );
201 data.read( "levy", lev.y );
202 data.read( "levz", lev.z );
203 data.read( "om_x", com.x );
204 data.read( "om_y", com.y );
205
206 load_map(
207 tripoint( lev.x + com.x * OMAPX * 2, lev.y + com.y * OMAPY * 2, lev.z ),
208 /*pump_events=*/true
209 );
210
211 safe_mode = static_cast<safe_mode_type>( tmprun );
212 if( get_option<bool>( "SAFEMODE" ) && safe_mode == SAFE_MODE_OFF ) {
214 }
215
216 std::string linebuff;
217 std::string linebuf;
218 if( data.read( "grscent", linebuf ) && data.read( "typescent", linebuff ) ) {
219 scent.deserialize( linebuf );
220 scent.deserialize( linebuff, true );
221 } else {
222 scent.reset();
223 }
224 data.read( "active_monsters", *critter_tracker );
225
226 coming_to_stairs.clear();
227 for( auto elem : data.get_array( "stair_monsters" ) ) {
228 monster stairtmp;
229 elem.read( stairtmp );
230 coming_to_stairs.push_back( stairtmp );
231 }
232
233 if( data.has_object( "kill_tracker" ) ) {
234 data.read( "kill_tracker", *kill_tracker_ptr );
235 } else {
236 // Legacy support for when kills were stored directly in game
237 std::map<mtype_id, int> kills;
238 std::vector<std::string> npc_kills;
239 for( const JsonMember member : data.get_object( "kills" ) ) {
240 kills[mtype_id( member.name() )] = member.get_int();
241 }
242
243 for( const std::string npc_name : data.get_array( "npc_kills" ) ) {
244 npc_kills.push_back( npc_name );
245 }
246
247 kill_tracker_ptr->reset( kills, npc_kills );
248 }
249
250 data.read( "player", u );
252 data.read( "stats_tracker", *stats_tracker_ptr );
253 data.read( "achievements_tracker", *achievements_tracker_ptr );
254 data.read( "token_provider", token_provider_ptr );
256 Messages::deserialize( data );
257
258 } catch( const JsonError &jsonerr ) {
259 debugmsg( "Bad save json\n%s", jsonerr.c_str() );
260 return;
261 }
262}
season_type
Real world seasons.
Definition: calendar.h:17
Represents a member of a JsonObject.
Definition: json.h:1249
JsonObject get_object(const std::string &name) const
Definition: json.cpp:429
bool has_object(const std::string &name) const
Definition: json.cpp:493
JsonArray get_array(const std::string &name) const
Definition: json.cpp:400
int get_int(const std::string &name) const
Definition: json.cpp:350
bool read(const std::string &name, T &t, bool throw_on_error=true) const
Definition: json.h:941
void deserialize(const std::string &data, bool is_type=false)
Definition: savegame.cpp:264
safe_mode_type
Definition: game.h:76
static constexpr int OMAPY
static constexpr int OMAPX
Size of the overmap.
void deserialize(const JsonObject &json)
Definition: messages.cpp:330
std::string member
Definition: mapgen.cpp:419
static void chkversion(std::istream &fin)
Definition: savegame.cpp:148
int savegame_loading_version
Definition: savegame.cpp:64

References calendar_config::_initial_season, calendar_config::_start_of_cataclysm, calendar_config::_start_of_game, achievements_tracker_ptr, auto_travel_mode, JsonError::c_str(), chkversion(), coming_to_stairs, calendar::config, critter_tracker, debugmsg, Messages::deserialize(), scent_map::deserialize(), time_duration::from_turns(), JsonObject::get_array(), JsonObject::get_int(), JsonIn::get_object(), JsonObject::get_object(), JsonObject::has_object(), inp_mngr, kill_tracker_ptr, load_map(), mapgen_defer::member, mostseen, mtype_id, OMAPX, OMAPY, input_manager::pump_events(), JsonObject::read(), scent_map::reset(), safe_mode, SAFE_MODE_OFF, SAFE_MODE_ON, savegame_loading_version, scent, SPRING, stats_tracker_ptr, token_provider_ptr, calendar::turn, calendar::turn_zero, u, point::x, tripoint::x, point::y, tripoint::y, and tripoint::z.

Referenced by load().

◆ unserialize_master()

void game::unserialize_master ( std::istream &  fin)

Definition at line 1193 of file savegame.cpp.

1194{
1196 chkversion( fin );
1197 if( savegame_loading_version < 11 ) {
1198 std::unique_ptr<static_popup>popup = std::make_unique<static_popup>();
1199 popup->message(
1200 _( "Cannot find loader for save data in old version %d, attempting to load as current version %d." ),
1204 }
1205 try {
1206 // single-pass parsing example
1207 JsonIn jsin( fin );
1208 jsin.start_object();
1209 while( !jsin.end_object() ) {
1210 std::string name = jsin.get_member_name();
1211 if( name == "next_mission_id" ) {
1212 next_mission_id = jsin.get_int();
1213 } else if( name == "next_npc_id" ) {
1214 next_npc_id.deserialize( jsin );
1215 } else if( name == "active_missions" ) {
1217 } else if( name == "factions" ) {
1218 jsin.read( *faction_manager_ptr );
1219 } else if( name == "seed" ) {
1220 jsin.read( seed );
1221 } else if( name == "weather" ) {
1222 JsonObject w = jsin.get_object();
1223 w.read( "lightning", get_weather().lightning_active );
1224 } else {
1225 // silently ignore anything else
1226 jsin.skip_value();
1227 }
1228 }
1229 } catch( const JsonError &e ) {
1230 debugmsg( "error loading %s: %s", SAVE_MASTER, e.c_str() );
1231 }
1232}
void deserialize(JsonIn &)
static void unserialize_all(JsonIn &jsin)
Definition: savegame.cpp:1183

References _, JsonError::c_str(), chkversion(), debugmsg, character_id::deserialize(), JsonIn::end_object(), faction_manager_ptr, JsonIn::get_int(), JsonIn::get_member_name(), JsonIn::get_object(), get_weather, om_direction::name(), next_mission_id, next_npc_id, popup(), JsonIn::read(), JsonObject::read(), ui_manager::redraw(), refresh_display(), SAVE_MASTER(), savegame_loading_version, savegame_version, seed, JsonIn::skip_value(), JsonIn::start_object(), and mission::unserialize_all().

Referenced by load_master().

◆ update_map() [1/2]

point game::update_map ( int &  x,
int &  y 
)

Definition at line 10694 of file game.cpp.

10695{
10696 point shift;
10697
10698 while( x < HALF_MAPSIZE_X ) {
10699 x += SEEX;
10700 shift.x--;
10701 }
10702 while( x >= HALF_MAPSIZE_X + SEEX ) {
10703 x -= SEEX;
10704 shift.x++;
10705 }
10706 while( y < HALF_MAPSIZE_Y ) {
10707 y += SEEY;
10708 shift.y--;
10709 }
10710 while( y >= HALF_MAPSIZE_Y + SEEY ) {
10711 y -= SEEY;
10712 shift.y++;
10713 }
10714
10715 if( shift == point_zero ) {
10716 // adjust player position
10717 u.setpos( tripoint( x, y, get_levz() ) );
10718 // Update what parts of the world map we can see
10719 // We need this call because even if the map hasn't shifted we may have changed z-level and can now see farther
10720 // TODO: only make this call if we changed z-level
10722 // Not actually shifting the submaps, all the stuff below would do nothing
10723 return point_zero;
10724 }
10725
10726 // this handles loading/unloading submaps that have scrolled on or off the viewport
10727 // NOLINTNEXTLINE(cata-use-named-point-constants)
10728 inclusive_rectangle<point> size_1( point( -1, -1 ), point( 1, 1 ) );
10729 point remaining_shift = shift;
10730 while( remaining_shift != point_zero ) {
10731 point this_shift = clamp( remaining_shift, size_1 );
10732 m.shift( this_shift );
10733 remaining_shift -= this_shift;
10734 }
10735
10736 grid_tracker_ptr->load( m );
10737
10738 // Shift monsters
10739 shift_monsters( tripoint( shift, 0 ) );
10740 const point shift_ms = sm_to_ms_copy( shift );
10741 u.shift_destination( -shift_ms );
10742
10743 // Shift NPCs
10744 for( auto it = active_npc.begin(); it != active_npc.end(); ) {
10745 ( *it )->shift( shift );
10746 if( ( *it )->posx() < 0 - SEEX * 2 || ( *it )->posy() < 0 - SEEX * 2 ||
10747 ( *it )->posx() > SEEX * ( MAPSIZE + 2 ) || ( *it )->posy() > SEEY * ( MAPSIZE + 2 ) ) {
10748 //Remove the npc from the active list. It remains in the overmap list.
10749 ( *it )->on_unload();
10750 it = active_npc.erase( it );
10751 } else {
10752 it++;
10753 }
10754 }
10755
10756 scent.shift( shift_ms );
10757
10758 // Also ensure the player is on current z-level
10759 // get_levz() should later be removed, when there is no longer such a thing
10760 // as "current z-level"
10761 u.setpos( tripoint( x, y, get_levz() ) );
10762
10763 // Only do the loading after all coordinates have been shifted.
10764
10765 // Check for overmap saved npcs that should now come into view.
10766 // Put those in the active list.
10767 load_npcs();
10768
10769 // Make sure map cache is consistent since it may have shifted.
10770 if( m.has_zlevels() ) {
10771 for( int zlev = -OVERMAP_DEPTH; zlev <= OVERMAP_HEIGHT; ++zlev ) {
10772 m.invalidate_map_cache( zlev );
10773 }
10774 } else {
10776 }
10778
10779 // Spawn monsters if appropriate
10780 // This call will generate new monsters in addition to loading, so it's placed after NPC loading
10781 m.spawn_monsters( false ); // Static monsters
10782
10783 // Update what parts of the world map we can see
10785
10786 return shift;
10787}
void shift_destination(point shift)
void shift_monsters(const tripoint &shift)
Shift all active monsters, the shift vector is the number of shifted submaps.
Definition: game.cpp:11063
void shift(point s)
Shift the map along the vector s.
Definition: map.cpp:6907
void shift(point sm_shift)
Definition: scent_map.cpp:82
point sm_to_ms_copy(point p)
static constexpr int HALF_MAPSIZE_Y
static constexpr int HALF_MAPSIZE_X

References active_npc, map::build_map_cache(), clamp(), get_levz(), grid_tracker_ptr, HALF_MAPSIZE_X, HALF_MAPSIZE_Y, map::has_zlevels(), map::invalidate_map_cache(), load_npcs(), m, MAPSIZE, OVERMAP_DEPTH, OVERMAP_HEIGHT, point_zero, scent, SEEX, SEEY, Character::setpos(), map::shift(), scent_map::shift(), Character::shift_destination(), shift_monsters(), sm_to_ms_copy(), map::spawn_monsters(), u, update_overmap_seen(), point::x, and point::y.

◆ update_map() [2/2]

point game::update_map ( player p)

Definition at line 10688 of file game.cpp.

10689{
10690 point p2( p.posx(), p.posy() );
10691 return update_map( p2.x, p2.y );
10692}

References Character::posx(), Character::posy(), update_map(), point::x, and point::y.

Referenced by fling_creature(), load(), place_player(), start_game(), update_map(), and vertical_move().

◆ update_overmap_seen()

void game::update_overmap_seen ( )

Definition at line 10789 of file game.cpp.

10790{
10791 const tripoint_abs_omt ompos = u.global_omt_location();
10792 const int dist = u.overmap_sight_range( light_level( u.posz() ) );
10793 const int dist_squared = dist * dist;
10794 // We can always see where we're standing
10795 overmap_buffer.set_seen( ompos, true );
10796 for( const tripoint_abs_omt &p : points_in_radius( ompos, dist ) ) {
10797 const point_rel_omt delta = p.xy() - ompos.xy();
10798 const int h_squared = delta.x() * delta.x() + delta.y() * delta.y();
10799 if( trigdist && h_squared > dist_squared ) {
10800 continue;
10801 }
10802 if( delta == point_rel_omt() ) {
10803 // 1. This case is already handled outside of the loop
10804 // 2. Calculating multiplier would cause division by zero
10805 continue;
10806 }
10807 // If circular distances are enabled, scale overmap distances by the diagonality of the sight line.
10808 point abs_delta = delta.raw().abs();
10809 int max_delta = std::max( abs_delta.x, abs_delta.y );
10810 const float multiplier = trigdist ? std::sqrt( h_squared ) / max_delta : 1;
10811 const std::vector<tripoint_abs_omt> line = line_to( ompos, p );
10812 float sight_points = dist;
10813 for( auto it = line.begin();
10814 it != line.end() && sight_points >= 0; ++it ) {
10815 const oter_id &ter = overmap_buffer.ter( *it );
10816 sight_points -= static_cast<int>( ter->get_see_cost() ) * multiplier;
10817 }
10818 if( sight_points >= 0 ) {
10819 tripoint_abs_omt seen( p );
10820 do {
10821 overmap_buffer.set_seen( seen, true );
10822 --seen.z();
10823 } while( seen.z() >= 0 );
10824 }
10825 }
10826}
bool trigdist
Circular distances.
int overmap_sight_range(int light_level) const
Returns the distance the player can see on the overmap.
Definition: character.cpp:658
constexpr Point & raw()
Definition: coordinates.h:111
void set_seen(const tripoint_abs_omt &p, bool seen=true)
coords::coord_point< point, coords::origin::relative, coords::omt > point_rel_omt
Definition: coordinates.h:478
tripoint_range< Tripoint > points_in_radius(const Tripoint &center, const int radius, const int radiusz=0)
Definition: map_iterator.h:125
unsigned char get_see_cost() const
Definition: omdata.h:230

References oter_t::get_see_cost(), Character::global_omt_location(), light_level(), line(), line_to(), overmap_buffer, Character::overmap_sight_range(), points_in_radius(), Character::posz(), coords::coord_point< Point, Origin, Scale >::raw(), overmapbuffer::set_seen(), overmapbuffer::ter(), trigdist, u, coords::coord_point< Point, Origin, Scale >::x(), point::x, coords::coord_point< Point, Origin, Scale >::xy(), coords::coord_point< Point, Origin, Scale >::y(), point::y, and coords::coord_point< Point, Origin, Scale >::z().

Referenced by place_player_overmap(), and update_map().

◆ update_stair_monsters()

void game::update_stair_monsters ( )
private
Dodge reduces chance of being downed when pushed off the stairs

Definition at line 10841 of file game.cpp.

10842{
10843 // Search for the stairs closest to the player.
10844 std::vector<int> stairx;
10845 std::vector<int> stairy;
10846 std::vector<int> stairdist;
10847
10848 const bool from_below = monstairz < get_levz();
10849
10850 if( coming_to_stairs.empty() ) {
10851 return;
10852 }
10853
10854 if( m.has_zlevels() ) {
10855 debugmsg( "%d monsters coming to stairs on a map with z-levels",
10856 coming_to_stairs.size() );
10857 coming_to_stairs.clear();
10858 }
10859
10860 for( const tripoint &dest : m.points_on_zlevel( u.posz() ) ) {
10861 if( ( from_below && m.has_flag( "GOES_DOWN", dest ) ) ||
10862 ( !from_below && m.has_flag( "GOES_UP", dest ) ) ) {
10863 stairx.push_back( dest.x );
10864 stairy.push_back( dest.y );
10865 stairdist.push_back( rl_dist( dest, u.pos() ) );
10866 }
10867 }
10868 if( stairdist.empty() ) {
10869 return; // Found no stairs?
10870 }
10871
10872 // Find closest stairs.
10873 size_t si = 0;
10874 for( size_t i = 0; i < stairdist.size(); i++ ) {
10875 if( stairdist[i] < stairdist[si] ) {
10876 si = i;
10877 }
10878 }
10879
10880 // Find up to 4 stairs for distance stairdist[si] +1
10881 std::vector<int> nearest;
10882 nearest.push_back( si );
10883 for( size_t i = 0; i < stairdist.size() && nearest.size() < 4; i++ ) {
10884 if( ( i != si ) && ( stairdist[i] <= stairdist[si] + 1 ) ) {
10885 nearest.push_back( i );
10886 }
10887 }
10888 // Randomize the stair choice
10889 si = random_entry_ref( nearest );
10890
10891 // Attempt to spawn zombies.
10892 for( size_t i = 0; i < coming_to_stairs.size(); i++ ) {
10893 point mpos( stairx[si], stairy[si] );
10894 monster &critter = coming_to_stairs[i];
10895 const tripoint dest {
10896 mpos, g->get_levz()
10897 };
10898
10899 // We might be not be visible.
10900 if( ( critter.posx() < 0 - ( MAPSIZE_X ) / 6 ||
10901 critter.posy() < 0 - ( MAPSIZE_Y ) / 6 ||
10902 critter.posx() > ( MAPSIZE_X * 7 ) / 6 ||
10903 critter.posy() > ( MAPSIZE_Y * 7 ) / 6 ) ) {
10904 continue;
10905 }
10906
10907 critter.staircount -= 4;
10908 // Let the player know zombies are trying to come.
10909 if( u.sees( dest ) ) {
10910 std::string dump;
10911 if( critter.staircount > 4 ) {
10912 dump += string_format( _( "You see a %s on the stairs" ), critter.name() );
10913 } else {
10914 if( critter.staircount > 0 ) {
10915 dump += ( from_below ?
10916 //~ The <monster> is almost at the <bottom/top> of the <terrain type>!
10917 string_format( _( "The %1$s is almost at the top of the %2$s!" ),
10918 critter.name(),
10919 m.tername( dest ) ) :
10920 string_format( _( "The %1$s is almost at the bottom of the %2$s!" ),
10921 critter.name(),
10922 m.tername( dest ) ) );
10923 }
10924 }
10925
10926 add_msg( m_warning, dump );
10927 } else {
10929 _( "a sound nearby from the stairs!" ), true, "misc", "stairs_movement" );
10930 }
10931
10932 if( critter.staircount > 0 ) {
10933 continue;
10934 }
10935
10936 if( is_empty( dest ) ) {
10937 critter.spawn( dest );
10938 critter.staircount = 0;
10939 place_critter_at( make_shared_fast<monster>( critter ), dest );
10940 if( u.sees( dest ) ) {
10941 if( !from_below ) {
10942 add_msg( m_warning, _( "The %1$s comes down the %2$s!" ),
10943 critter.name(),
10944 m.tername( dest ) );
10945 } else {
10946 add_msg( m_warning, _( "The %1$s comes up the %2$s!" ),
10947 critter.name(),
10948 m.tername( dest ) );
10949 }
10950 }
10951 coming_to_stairs.erase( coming_to_stairs.begin() + i );
10952 continue;
10953 } else if( u.pos() == dest ) {
10954 // Monster attempts to push player of stairs
10956 int tries = 0;
10957
10958 // the critter is now right on top of you and will attack unless
10959 // it can find a square to push you into with one of his tries.
10960 const int creature_push_attempts = 9;
10961 const int player_throw_resist_chance = 3;
10962
10963 critter.spawn( dest );
10964 while( tries < creature_push_attempts ) {
10965 tries++;
10966 push.x = rng( -1, 1 );
10967 push.y = rng( -1, 1 );
10968 point ipos( mpos + push );
10969 tripoint pos( ipos, get_levz() );
10970 if( ( push.x != 0 || push.y != 0 ) && !critter_at( pos ) &&
10971 critter.can_move_to( pos ) ) {
10972 bool resiststhrow = ( u.is_throw_immune() ) ||
10974 if( resiststhrow && one_in( player_throw_resist_chance ) ) {
10975 u.moves -= 25; // small charge for avoiding the push altogether
10976 add_msg( _( "The %s fails to push you back!" ),
10977 critter.name() );
10978 return; //judo or leg brace prevent you from getting pushed at all
10979 }
10980 // Not accounting for tentacles latching on, so..
10981 // Something is about to happen, lets charge half a move
10982 u.moves -= 50;
10983 if( resiststhrow && ( u.is_throw_immune() ) ) {
10984 //we have a judoka who isn't getting pushed but counterattacking now.
10985 mattack::thrown_by_judo( &critter );
10986 return;
10987 }
10988 std::string msg;
10989 ///\EFFECT_DODGE reduces chance of being downed when pushed off the stairs
10990 if( !( resiststhrow ) && ( u.get_dodge() + rng( 0, 3 ) < 12 ) ) {
10991 // dodge 12 - never get downed
10992 // 11.. avoid 75%; 10.. avoid 50%; 9.. avoid 25%
10993 u.add_effect( effect_downed, 2_turns );
10994 msg = _( "The %s pushed you back hard!" );
10995 } else {
10996 msg = _( "The %s pushed you back!" );
10997 }
10998 add_msg( m_warning, msg.c_str(), critter.name() );
10999 u.setx( u.posx() + push.x );
11000 u.sety( u.posy() + push.y );
11001 return;
11002 }
11003 }
11005 _( "The %s tried to push you back but failed! It attacks you!" ),
11006 critter.name() );
11007 critter.melee_attack( u );
11008 u.moves -= 50;
11009 return;
11010 } else if( monster *const mon_ptr = critter_at<monster>( dest ) ) {
11011 // Monster attempts to displace a monster from the stairs
11012 monster &other = *mon_ptr;
11013 critter.spawn( dest );
11014
11015 // the critter is now right on top of another and will push it
11016 // if it can find a square to push it into inside of his tries.
11017 const int creature_push_attempts = 9;
11018 const int creature_throw_resist = 4;
11019
11020 int tries = 0;
11021 point push2;
11022 while( tries < creature_push_attempts ) {
11023 tries++;
11024 push2.x = rng( -1, 1 );
11025 push2.y = rng( -1, 1 );
11026 point ipos2( mpos + push2 );
11027 tripoint pos( ipos2, get_levz() );
11028 if( ( push2.x == 0 && push2.y == 0 ) || ( ( ipos2.x == u.posx() ) && ( ipos2.y == u.posy() ) ) ) {
11029 continue;
11030 }
11031 if( !critter_at( pos ) && other.can_move_to( pos ) ) {
11032 other.setpos( tripoint( ipos2, get_levz() ) );
11033 other.moves -= 50;
11034 std::string msg;
11035 if( one_in( creature_throw_resist ) ) {
11036 other.add_effect( effect_downed, 2_turns );
11037 msg = _( "The %1$s pushed the %2$s hard." );
11038 } else {
11039 msg = _( "The %1$s pushed the %2$s." );
11040 }
11041 add_msg( m_neutral, msg, critter.name(), other.name() );
11042 return;
11043 }
11044 }
11045 return;
11046 }
11047 }
11048}
void setx(int x)
Definition: character.h:804
void sety(int y)
Definition: character.h:807
bool is_throw_immune() const
Returns true if the player is immune to throws.
float get_dodge() const override
Definition: melee.cpp:866
int monstairz
Definition: game.h:983
tripoint_range< tripoint > points_on_zlevel() const
Yields a range of all points that are contained in the map and have the z-level of this map (abs_sub)...
Definition: map.cpp:8783
bool can_move_to(const tripoint &p) const
Checks whether we can move to/through p.
Definition: monmove.cpp:261
int posy() const override
Definition: monster.h:498
void melee_attack(Creature &target)
Definition: monster.cpp:1419
int staircount
Definition: monster.h:509
void spawn(const tripoint &p)
Definition: monster.cpp:478
int posx() const override
Definition: monster.h:495
bool thrown_by_judo(monster *z)
Definition: monattack.cpp:4675
std::enable_if<!is_std_array< C >::value, constV & >::type random_entry_ref(const C &container)
Same as above, but with a statically allocated default value (using the default constructor).
Definition: rng.h:149

References _, Creature::add_effect(), add_msg(), monster::can_move_to(), coming_to_stairs, critter_at(), debugmsg, anonymous_namespace{iexamine_elevator.cpp}::elevator::dest(), effect_downed, g, Character::get_dodge(), get_levz(), map::has_flag(), Character::has_trait(), map::has_zlevels(), is_empty(), Character::is_throw_immune(), m, m_neutral, m_warning, MAPSIZE_X, MAPSIZE_Y, monster::melee_attack(), monstairz, sounds::movement, Creature::moves, monster::name(), one_in(), other, place_critter_at(), point_north_west, map::points_on_zlevel(), Character::pos(), Character::posx(), monster::posx(), Character::posy(), monster::posy(), Character::posz(), monexamine::push(), random_entry_ref(), rl_dist(), rng(), Character::sees(), Character::setx(), Character::sety(), sounds::sound(), monster::spawn(), monster::staircount, string_format(), map::tername(), mattack::thrown_by_judo(), trait_LEG_TENT_BRACE, u, point::x, and point::y.

Referenced by do_turn(), and vertical_move().

◆ update_zombie_pos()

bool game::update_zombie_pos ( const monster critter,
const tripoint pos 
)

Redirects to the creature_tracker update_pos() function.

Definition at line 4729 of file game.cpp.

4730{
4731 return critter_tracker->update_pos( critter, pos );
4732}

References critter_tracker.

◆ use_computer()

void game::use_computer ( const tripoint p)

Checks to see if a player can use a computer (not illiterate, etc.) and uses if able.

Definition at line 4512 of file game.cpp.

4513{
4514 if( u.has_trait( trait_id( "ILLITERATE" ) ) ) {
4515 add_msg( m_info, _( "You can not read a computer screen!" ) );
4516 return;
4517 }
4518 if( u.is_blind() ) {
4519 // we don't have screen readers in game
4520 add_msg( m_info, _( "You can not see a computer screen!" ) );
4521 return;
4522 }
4523 if( u.has_trait( trait_id( "HYPEROPIC" ) ) && !u.worn_with_flag( "FIX_FARSIGHT" ) &&
4524 !u.has_effect( effect_contacts ) && !u.has_bionic( bionic_id( "bio_eye_optic" ) ) ) {
4525 add_msg( m_info, _( "You'll need to put on reading glasses before you can see the screen." ) );
4526 return;
4527 }
4528
4529 computer *used = m.computer_at( p );
4530
4531 if( used == nullptr ) {
4532 if( m.has_flag( "CONSOLE", p ) ) { //Console without map data
4533 add_msg( m_bad, _( "The console doesn't display anything coherent." ) );
4534 } else {
4535 debugmsg( "Tried to use computer at %s - none there", p.to_string() );
4536 }
4537 return;
4538 }
4539
4540 computer_session( *used ).use();
4541}
void use()
Handles player use of a computer.
computer * computer_at(const tripoint &p)
Definition: map.cpp:5682
static const efftype_id effect_contacts("contacts")

References _, add_msg(), map::computer_at(), debugmsg, effect_contacts, Character::has_bionic(), Creature::has_effect(), map::has_flag(), Character::has_trait(), Character::is_blind(), m, m_bad, m_info, tripoint::to_string(), u, computer_session::use(), and Character::worn_with_flag().

Referenced by examine().

◆ validate_camps()

void game::validate_camps ( )

validate camps to ensure they are on the overmap list

Definition at line 1952 of file game.cpp.

1953{
1954 basecamp camp = m.hoist_submap_camp( u.pos() );
1955 if( camp.is_valid() ) {
1956 overmap_buffer.add_camp( camp );
1958 } else if( camp.camp_omt_pos() != tripoint_abs_omt() ) {
1959 std::string camp_name = _( "Faction Camp" );
1960 camp.set_name( camp_name );
1961 overmap_buffer.add_camp( camp );
1963 }
1964}
bool is_valid() const
Definition: basecamp.h:125
void set_name(const std::string &new_name)
Definition: basecamp.cpp:575
tripoint_abs_omt camp_omt_pos() const
Definition: basecamp.h:134
basecamp hoist_submap_camp(const tripoint &p)
Definition: map.cpp:5713
void remove_submap_camp(const tripoint &)
Definition: map.cpp:5708
void add_camp(const basecamp &camp)
Add Basecamp to overmapbuffer.

References _, overmapbuffer::add_camp(), basecamp::camp_omt_pos(), map::hoist_submap_camp(), basecamp::is_valid(), m, overmap_buffer, Character::pos(), map::remove_submap_camp(), basecamp::set_name(), and u.

Referenced by load().

◆ validate_linked_vehicles()

void game::validate_linked_vehicles ( )

validate towed vehicles so they get linked up again after a load

Definition at line 1894 of file game.cpp.

1895{
1896 for( auto &veh : m.get_vehicles() ) {
1897 vehicle *v = veh.v;
1900 if( other_v ) {
1901 // the other vehicle is towing us.
1902 v->tow_data.set_towing( other_v, v );
1904 }
1905 }
1906 }
1907}
tripoint other_towing_point
Definition: vehicle.h:166
bool set_towing(vehicle *tower_veh, vehicle *towed_veh)
Definition: vehicle.cpp:6140
towing_data tow_data
Definition: vehicle.h:1676

References map::get_vehicles(), m, towing_data::other_towing_point, towing_data::set_towing(), vehicle::tow_data, tripoint_zero, map::veh_at(), and veh_pointer_or_null().

Referenced by load().

◆ validate_mounted_npcs()

void game::validate_mounted_npcs ( )

Definition at line 1909 of file game.cpp.

1910{
1911 for( monster &m : all_monsters() ) {
1912 if( m.has_effect( effect_ridden ) && m.mounted_player_id.is_valid() ) {
1913 player *mounted_pl = g->critter_by_id<player>( m.mounted_player_id );
1914 if( !mounted_pl ) {
1915 // Target no longer valid.
1916 m.mounted_player_id = character_id();
1917 m.remove_effect( effect_ridden );
1918 continue;
1919 }
1920 mounted_pl->mounted_creature = shared_from( m );
1921 mounted_pl->setpos( m.pos() );
1922 mounted_pl->add_effect( effect_riding, 1_turns, num_bp );
1923 m.mounted_player = mounted_pl;
1924 }
1925 }
1926}

References Creature::add_effect(), all_monsters(), character_id, effect_ridden, effect_riding, g, m, Character::mounted_creature, num_bp, Character::setpos(), and shared_from().

Referenced by load(), and vertical_shift().

◆ validate_npc_followers()

void game::validate_npc_followers ( )

validate list of followers to account for overmap buffers

Definition at line 1928 of file game.cpp.

1929{
1930 // Make sure visible followers are in the list.
1931 const std::vector<npc *> visible_followers = get_npcs_if( [&]( const npc & guy ) {
1932 return guy.is_player_ally();
1933 } );
1934 for( npc *guy : visible_followers ) {
1935 update_faction_api( guy );
1936 add_npc_follower( guy->getID() );
1937 }
1938 // Make sure overmapbuffered NPC followers are in the list.
1939 for( const auto &temp_guy : overmap_buffer.get_npcs_near_player( 300 ) ) {
1940 npc *guy = temp_guy.get();
1941 if( guy->is_player_ally() ) {
1942 update_faction_api( guy );
1943 add_npc_follower( guy->getID() );
1944 }
1945 }
1946 // Make sure that serialized player followers sync up with game list
1947 for( const auto &temp_id : u.follower_ids ) {
1948 add_npc_follower( temp_id );
1949 }
1950}
void add_npc_follower(const character_id &id)
Add follower id to set of followers.
Definition: game.cpp:1874
static void update_faction_api(npc *guy)
Definition: game.cpp:1886

References add_npc_follower(), player::follower_ids, get_npcs_if(), overmapbuffer::get_npcs_near_player(), Character::getID(), npc::is_player_ally(), overmap_buffer, u, and update_faction_api().

Referenced by load().

◆ vertical_move()

void game::vertical_move ( int  z,
bool  force,
bool  peeking = false 
)

Moves the player vertically.

If force == true then they are falling. If peeking == true, forbids some exotic movement options

Strength increases breath-holding capacity while diving Dexterity increases chance of moving past monsters on stairs Dodge increases chance of moving past monsters on stairs Strength increases chance of moving past monsters on stairs Melee increases chance of moving past monsters on stairs

Definition at line 10014 of file game.cpp.

10015{
10016 if( u.is_mounted() ) {
10017 auto mons = u.mounted_creature.get();
10018 if( mons->has_flag( MF_RIDEABLE_MECH ) ) {
10019 if( !mons->check_mech_powered() ) {
10020 add_msg( m_bad, _( "Your %s refuses to move as its batteries have been drained." ),
10021 mons->get_name() );
10022 return;
10023 }
10024 }
10025 }
10026
10027 // > and < are used for diving underwater.
10028 if( m.has_flag( "SWIMMABLE", u.pos() ) && m.has_flag( TFLAG_DEEP_WATER, u.pos() ) ) {
10029 if( movez == -1 ) {
10030 if( u.is_underwater() ) {
10031 add_msg( m_info, _( "You are already underwater!" ) );
10032 return;
10033 }
10034 if( u.worn_with_flag( "FLOTATION" ) ) {
10035 add_msg( m_info, _( "You can't dive while wearing a flotation device." ) );
10036 return;
10037 }
10038 u.set_underwater( true );
10039 ///\EFFECT_STR increases breath-holding capacity while diving
10040 u.oxygen = 30 + 2 * u.str_cur;
10041 add_msg( _( "You dive underwater!" ) );
10042 } else {
10043 if( u.swim_speed() < 500 || u.shoe_type_count( itype_swim_fins ) ) {
10044 u.set_underwater( false );
10045 add_msg( _( "You surface." ) );
10046 } else {
10047 add_msg( m_info, _( "You try to surface but can't!" ) );
10048 }
10049 }
10050 u.moves -= 100;
10051 return;
10052 }
10053
10054 // Force means we're going down, even if there's no staircase, etc.
10055 bool climbing = false;
10056 int move_cost = 100;
10057 tripoint stairs( u.posx(), u.posy(), u.posz() + movez );
10058 if( m.has_zlevels() && !force && movez == 1 && !m.has_flag( "GOES_UP", u.pos() ) ) {
10059 // Climbing
10060 if( m.has_floor_or_support( stairs ) ) {
10061 add_msg( m_info, _( "You can't climb here - there's a ceiling above your head." ) );
10062 return;
10063 }
10064
10065 std::vector<tripoint> pts;
10066 for( const auto &pt : m.points_in_radius( stairs, 1 ) ) {
10067 if( m.passable( pt ) &&
10068 m.has_floor_or_support( pt ) ) {
10069 pts.push_back( pt );
10070 }
10071 }
10072
10073
10074 const auto cost = map_funcs::climbing_cost( m, u.pos(), stairs );
10075
10076 if( !cost.has_value() ) {
10077 if( u.has_trait( trait_WEB_ROPE ) ) {
10078 if( pts.empty() ) {
10079 add_msg( m_info, _( "There is nothing above you that you can attach a web to." ) );
10080 } else if( can_use_mutation_warn( trait_WEB_ROPE, u ) ) {
10081 if( m.move_cost( u.pos() ) != 2 && m.move_cost( u.pos() ) != 3 ) {
10082 add_msg( m_info, _( "You can't spin a web rope there." ) );
10083 } else if( m.has_furn( u.pos() ) ) {
10084 add_msg( m_info, _( "There is already furniture at that location." ) );
10085 } else {
10086 if( query_yn( "Spin a rope and climb?" ) ) {
10087 add_msg( m_good, _( "You spin a rope of web." ) );
10088 m.furn_set( u.pos(), furn_str_id( "f_rope_up_web" ) );
10089 u.mod_moves( to_turns<int>( 2_seconds ) );
10091 vertical_move( movez, force, peeking );
10092 }
10093 }
10094 }
10095
10096 } else {
10097 add_msg( m_info, _( "You can't climb here - you need walls and/or furniture to brace against." ) );
10098
10099 }
10100 return;
10101
10102 }
10103
10104 if( pts.empty() ) {
10105 add_msg( m_info,
10106 _( "You can't climb here - there is no terrain above you that would support your weight." ) );
10107 return;
10108 } else {
10109 // TODO: Make it an extended action
10110 climbing = true;
10111 move_cost = cost.value();
10112
10113 const std::optional<tripoint> pnt = point_selection_menu( pts );
10114 if( !pnt ) {
10115 return;
10116 }
10117 stairs = *pnt;
10118 }
10119 }
10120
10121 if( !force && movez == -1 && !m.has_flag( "GOES_DOWN", u.pos() ) ) {
10122 add_msg( m_info, _( "You can't go down here!" ) );
10123 return;
10124 } else if( !climbing && !force && movez == 1 && !m.has_flag( "GOES_UP", u.pos() ) ) {
10125 add_msg( m_info, _( "You can't go up here!" ) );
10126 return;
10127 }
10128
10129 if( force ) {
10130 // Let go of a grabbed cart.
10131 u.grab( OBJECT_NONE );
10132 } else if( u.grab_point != tripoint_zero ) {
10133 add_msg( m_info, _( "You can't drag things up and down stairs." ) );
10134 return;
10135 }
10136
10137 // Because get_levz takes z-value from the map, it will change when vertical_shift (m.has_zlevels() == true)
10138 // is called or when the map is loaded on new z-level (== false).
10139 // This caches the z-level we start the movement on (current) and the level we're want to end.
10140 const int z_before = get_levz();
10141 const int z_after = get_levz() + movez;
10142 if( z_after < -OVERMAP_DEPTH || z_after > OVERMAP_HEIGHT ) {
10143 debugmsg( "Tried to move outside allowed range of z-levels" );
10144 return;
10145 }
10146
10147 if( !u.move_effects( false ) ) {
10148 return;
10149 }
10150
10151 // Check if there are monsters are using the stairs.
10152 bool slippedpast = false;
10153 if( !m.has_zlevels() && !coming_to_stairs.empty() && !force ) {
10154 // TODO: Allow travel if zombie couldn't reach stairs, but spawn him when we go up.
10155 add_msg( m_warning, _( "You try to use the stairs. Suddenly you are blocked by a %s!" ),
10156 coming_to_stairs[0].name() );
10157 // Roll.
10158 ///\EFFECT_DEX increases chance of moving past monsters on stairs
10159
10160 ///\EFFECT_DODGE increases chance of moving past monsters on stairs
10161 int dexroll = dice( 6, u.dex_cur + u.get_skill_level( skill_dodge ) * 2 );
10162 ///\EFFECT_STR increases chance of moving past monsters on stairs
10163
10164 ///\EFFECT_MELEE increases chance of moving past monsters on stairs
10165 int strroll = dice( 3, u.str_cur + u.get_skill_level( skill_melee ) * 1.5 );
10166 if( coming_to_stairs.size() > 4 ) {
10167 add_msg( _( "The are a lot of them on the %s!" ), m.tername( u.pos() ) );
10168 dexroll /= 4;
10169 strroll /= 2;
10170 } else if( coming_to_stairs.size() > 1 ) {
10171 add_msg( m_warning, _( "There's something else behind it!" ) );
10172 dexroll /= 2;
10173 }
10174
10175 if( dexroll < 14 || strroll < 12 ) {
10177 u.moves -= 100;
10178 return;
10179 }
10180
10181 add_msg( _( "You manage to slip past!" ) );
10182 slippedpast = true;
10183 u.moves -= 100;
10184 }
10185
10186 // Shift the map up or down
10187
10188 std::unique_ptr<map> tmp_map_ptr;
10189 if( !m.has_zlevels() ) {
10190 tmp_map_ptr = std::make_unique<map>();
10191 }
10192
10193 map &maybetmp = m.has_zlevels() ? m : *( tmp_map_ptr.get() );
10194 if( m.has_zlevels() ) {
10195 // We no longer need to shift the map here! What joy
10196 } else {
10197 maybetmp.load( tripoint( get_levx(), get_levy(), z_after ), false );
10198 }
10199
10200 // Find the corresponding staircase
10201 bool rope_ladder = false;
10202 // TODO: Remove the stairfinding, make the mapgen gen aligned maps
10203 if( !force && !climbing ) {
10204 const std::optional<tripoint> pnt = find_or_make_stairs( maybetmp, z_after, rope_ladder, peeking );
10205 if( !pnt ) {
10206 return;
10207 }
10208 stairs = *pnt;
10209 }
10210
10211 if( !force ) {
10212 monstairz = z_before;
10213 }
10214 // Save all monsters that can reach the stairs, remove them from the tracker,
10215 // then despawn the remaining monsters. Because it's a vertical shift, all
10216 // monsters are out of the bounds of the map and will despawn.
10217 shared_ptr_fast<monster> stored_mount;
10218 if( u.is_mounted() && !m.has_zlevels() ) {
10219 // Store a *copy* of the mount, so we can remove the original monster instance
10220 // from the tracker before the map shifts.
10221 // Map shifting would otherwise just despawn the mount and would later respawn it.
10222 stored_mount = make_shared_fast<monster>( *u.mounted_creature );
10224 }
10225 if( !m.has_zlevels() ) {
10226 const tripoint to = u.pos();
10227 for( monster &critter : all_monsters() ) {
10228 // if its a ladder instead of stairs - most zombies can't climb that.
10229 // unless that have a special flag to allow them to do so.
10230 if( ( m.has_flag( "DIFFICULT_Z", u.pos() ) && !critter.climbs() ) ||
10231 critter.has_effect( effect_ridden ) ||
10232 critter.has_effect( effect_tied ) ) {
10233 continue;
10234 }
10235 int turns = critter.turns_to_reach( to.xy() );
10236 if( turns < 10 && coming_to_stairs.size() < 8 && critter.will_reach( to.xy() )
10237 && !slippedpast ) {
10238 critter.staircount = 10 + turns;
10239 critter.on_unload();
10240 coming_to_stairs.push_back( critter );
10241 remove_zombie( critter );
10242 }
10243 }
10244 auto mons = critter_tracker->find( g->u.pos() );
10245 if( mons != nullptr ) {
10246 critter_tracker->remove( *mons );
10247 }
10248 shift_monsters( tripoint( 0, 0, movez ) );
10249 }
10250
10251 std::vector<shared_ptr_fast<npc>> npcs_to_bring;
10252 std::vector<monster *> monsters_following;
10253 if( !m.has_zlevels() && std::abs( movez ) == 1 ) {
10254 std::copy_if( active_npc.begin(), active_npc.end(), back_inserter( npcs_to_bring ),
10255 [this]( const shared_ptr_fast<npc> &np ) {
10256 return np->is_walking_with() && !np->is_mounted() && !np->in_sleep_state() &&
10257 rl_dist( np->pos(), u.pos() ) < 2;
10258 } );
10259 }
10260
10261 if( m.has_zlevels() && std::abs( movez ) == 1 ) {
10262 bool ladder = m.has_flag( "DIFFICULT_Z", u.pos() );
10263 for( monster &critter : all_monsters() ) {
10264 if( ladder && !critter.climbs() ) {
10265 continue;
10266 }
10267 if( critter.attack_target() == &g->u || ( !critter.has_effect( effect_ridden ) &&
10268 critter.has_effect( effect_pet ) && critter.friendly == -1 &&
10269 !critter.has_effect( effect_tied ) ) ) {
10270 monsters_following.push_back( &critter );
10271 }
10272 }
10273 }
10274
10275 if( u.is_mounted() ) {
10276 monster *crit = u.mounted_creature.get();
10277 if( crit->has_flag( MF_RIDEABLE_MECH ) ) {
10278 crit->use_mech_power( -1 );
10279 if( u.movement_mode_is( CMM_WALK ) ) {
10280 crit->use_mech_power( -2 );
10281 } else if( u.movement_mode_is( CMM_CROUCH ) ) {
10282 crit->use_mech_power( -1 );
10283 } else if( u.movement_mode_is( CMM_RUN ) ) {
10284 crit->use_mech_power( -3 );
10285 }
10286 }
10287 } else {
10288 u.moves -= move_cost;
10289 }
10290 for( const auto &np : npcs_to_bring ) {
10291 if( np->in_vehicle ) {
10292 m.unboard_vehicle( np->pos() );
10293 }
10294 }
10295 const tripoint old_pos = g->u.pos();
10296 point submap_shift;
10297 vertical_shift( z_after );
10298 if( !force ) {
10299 submap_shift = update_map( stairs.x, stairs.y );
10300 }
10301
10302 // if an NPC or monster is on the stiars when player ascends/descends
10303 // they may end up merged on th esame tile, do some displacement to resolve that.
10304 // if, in the weird case of it not being possible to displace;
10305 // ( how did the player even manage to approach the stairs, if so? )
10306 // then nothing terrible happens, its just weird.
10307 if( critter_at<npc>( u.pos(), true ) || critter_at<monster>( u.pos(), true ) ) {
10308 std::string crit_name;
10309 bool player_displace = false;
10310 std::optional<tripoint> displace = find_empty_spot_nearby( u.pos() );
10311 if( displace.has_value() ) {
10312 npc *guy = g->critter_at<npc>( u.pos(), true );
10313 if( guy ) {
10314 crit_name = guy->get_name();
10315 tripoint old_pos = guy->pos();
10316 if( !guy->is_enemy() ) {
10317 guy->move_away_from( u.pos(), true );
10318 if( old_pos != guy->pos() ) {
10319 add_msg( _( "%s moves out of the way for you." ), guy->get_name() );
10320 }
10321 } else {
10322 player_displace = true;
10323 }
10324 }
10325 monster *mon = g->critter_at<monster>( u.pos(), true );
10326 // if the monster is ridden by the player or an NPC:
10327 // Dont displace them. If they are mounted by a friendly NPC,
10328 // then the NPC will already have been displaced just above.
10329 // if they are ridden by the player, we want them to coexist on same tile
10330 if( mon && !mon->mounted_player ) {
10331 crit_name = mon->get_name();
10332 if( mon->friendly == -1 ) {
10333 mon->setpos( *displace );
10334 add_msg( _( "Your %s moves out of the way for you." ), mon->get_name() );
10335 } else {
10336 player_displace = true;
10337 }
10338 }
10339 if( player_displace ) {
10340 u.setpos( *displace );
10341 u.moves -= 20;
10342 add_msg( _( "You push past %s blocking the way." ), crit_name );
10343 }
10344 } else {
10345 debugmsg( "Failed to find a spot to displace into." );
10346 }
10347 }
10348
10349 // Now that we know the player's destination position, we can move their mount as well
10350 if( u.is_mounted() ) {
10351 if( stored_mount ) {
10352 assert( !m.has_zlevels() );
10353 stored_mount->spawn( g->u.pos() );
10354 if( critter_tracker->add( stored_mount ) ) {
10355 u.mounted_creature = stored_mount;
10356 }
10357 } else {
10358 u.mounted_creature->setpos( g->u.pos() );
10359 }
10360 }
10361
10362 if( !npcs_to_bring.empty() ) {
10363 // Would look nicer randomly scrambled
10364 std::vector<tripoint> candidates = closest_points_first( u.pos(), 1 );
10365 candidates.erase( std::remove_if( candidates.begin(), candidates.end(),
10366 [this]( const tripoint & c ) {
10367 return !is_empty( c );
10368 } ), candidates.end() );
10369
10370 for( const auto &np : npcs_to_bring ) {
10371 const auto found = std::find_if( candidates.begin(), candidates.end(),
10372 [this, np]( const tripoint & c ) {
10373 return !np->is_dangerous_fields( m.field_at( c ) ) && m.tr_at( c ).is_benign();
10374 } );
10375 if( found != candidates.end() ) {
10376 // TODO: De-uglify
10377 np->setpos( *found );
10378 np->place_on_map();
10379 np->setpos( *found );
10380 candidates.erase( found );
10381 }
10382
10383 if( candidates.empty() ) {
10384 break;
10385 }
10386 }
10387
10388 reload_npcs();
10389 }
10390
10391 // This ugly check is here because of stair teleport bullshit
10392 // TODO: Remove stair teleport bullshit
10393 if( rl_dist( g->u.pos(), old_pos ) <= 1 ) {
10394 for( monster *m : monsters_following ) {
10395 m->set_dest( g->u.pos() );
10396 }
10397 }
10398
10399 if( rope_ladder ) {
10400 m.ter_set( u.pos(), t_rope_up );
10401 }
10402
10403 if( m.ter( stairs ) == t_manhole_cover ) {
10404 m.spawn_item( stairs + point( rng( -1, 1 ), rng( -1, 1 ) ), itype_manhole_cover );
10405 m.ter_set( stairs, t_manhole );
10406 }
10407
10408 // Wouldn't work and may do strange things
10409 if( u.is_hauling() && !m.has_zlevels() ) {
10410 add_msg( _( "You cannot haul items here." ) );
10411 u.stop_hauling();
10412 }
10413
10414 if( u.is_hauling() ) {
10415 const tripoint adjusted_pos = old_pos - sm_to_ms_copy( submap_shift );
10416 start_hauling( adjusted_pos );
10417 }
10418
10419 m.invalidate_map_cache( g->get_levz() );
10420 // Upon force movement, traps can not be avoided.
10421 m.creature_on_trap( u, !force );
10422
10424}
static int move_cost(const item &it, const tripoint &src, const tripoint &dest)
@ CMM_WALK
Definition: character.h:109
@ CMM_CROUCH
Definition: character.h:111
bool move_effects(bool attacking) override
Processes effects which may prevent the Character from moving (bear traps, crushed,...
Definition: character.cpp:1476
int swim_speed() const
Returns the player's speed for swimming across water tiles.
Definition: character.cpp:817
int oxygen
Definition: character.h:1591
void mutation_spend_resources(const trait_id &mut)
Removes the appropriate costs (NOTE: will reapply mods & recalc sightlines in case of newly activated...
Definition: mutation.cpp:1698
int shoe_type_count(const itype_id &it) const
Returns 1 if the player is wearing an item of that count on one foot, 2 if on both,...
Definition: character.cpp:8954
std::string get_name() const override
Definition: character.cpp:6004
void set_underwater(bool x) override
void start_hauling(const tripoint &pos)
Definition: game.cpp:10426
std::optional< tripoint > find_or_make_stairs(map &mp, int z_after, bool &rope_ladder, bool peeking)
Returns the other end of the stairs (if any).
Definition: game.cpp:10461
bool use_mech_power(int amt)
Definition: monster.cpp:2440
Character * mounted_player
Definition: monster.h:458
static const efftype_id effect_tied("tied")
static const itype_id itype_manhole_cover("manhole_cover")
static std::optional< tripoint > point_selection_menu(const std::vector< tripoint > &pts)
Definition: game.cpp:9964
static const skill_id skill_melee("melee")
static const itype_id itype_swim_fins("swim_fins")
static const trait_id trait_WEB_ROPE("WEB_ROPE")
ter_id t_rope_up
Definition: mapdata.cpp:722
ter_id t_manhole
Definition: mapdata.cpp:721
bool can_use_mutation_warn(const trait_id &mut, const Character &character)
Calls can_use_mutation and if it fails, print a standard message.
Definition: mutation.cpp:1687
void avatar_moves(const avatar &u, const map &m, const tripoint &p)
Definition: game.cpp:12100
int ladder(player *, item *, bool, const tripoint &)
Definition: iuse.cpp:9325
auto climbing_cost(const map &m, const tripoint &from, const tripoint &to) -> std::optional< int >
Checks both the neighborhoods of from and to for climbable surfaces, returns move cost of climbing fr...
point displace(type dir, int dist=1)
Returns point(0, 0) displaced in specified direction by a specified distance.
Definition: overmap.cpp:4191

References _, active_npc, add_msg(), all_monsters(), cata_event_dispatch::avatar_moves(), c, can_use_mutation_warn(), map_funcs::climbing_cost(), closest_points_first(), CMM_CROUCH, CMM_RUN, CMM_WALK, coming_to_stairs, map::creature_on_trap(), critter_tracker, debugmsg, Character::dex_cur, dice(), om_direction::displace(), effect_pet, effect_ridden, effect_tied, find_empty_spot_nearby(), find_or_make_stairs(), monster::friendly, map::furn_set(), g, get_levx(), get_levy(), get_levz(), Character::get_name(), monster::get_name(), Character::get_skill_level(), avatar::grab(), player::grab_point, map::has_flag(), monster::has_flag(), map::has_floor_or_support(), map::has_furn(), Character::has_trait(), map::has_zlevels(), map::invalidate_map_cache(), npc::is_enemy(), Character::is_hauling(), Character::is_mounted(), Creature::is_underwater(), itype_manhole_cover, itype_swim_fins, iuse::ladder(), map::load(), m, m_bad, m_good, m_info, m_warning, MF_RIDEABLE_MECH, Creature::mod_moves(), monstairz, Character::mounted_creature, monster::mounted_player, npc::move_away_from(), move_cost(), map::move_cost(), Character::move_effects(), Character::movement_mode_is(), Creature::moves, Character::mutation_spend_resources(), om_direction::name(), OBJECT_NONE, OVERMAP_HEIGHT, Character::oxygen, map::passable(), point_selection_menu(), map::points_in_radius(), Character::pos(), Character::posx(), Character::posy(), Character::posz(), query_yn(), reload_npcs(), remove_zombie(), rl_dist(), rng(), Character::set_underwater(), Character::setpos(), monster::setpos(), shift_monsters(), Character::shoe_type_count(), skill_dodge, skill_melee, sm_to_ms_copy(), map::spawn_item(), start_hauling(), Character::stop_hauling(), Character::str_cur, Character::swim_speed(), t_manhole, t_manhole_cover, t_rope_up, map::ter(), map::ter_set(), map::tername(), TFLAG_DEEP_WATER, trait_WEB_ROPE, tripoint_zero, u, map::unboard_vehicle(), update_map(), update_stair_monsters(), monster::use_mech_power(), vertical_move(), vertical_shift(), Character::worn_with_flag(), tripoint::x, tripoint::xy(), and tripoint::y.

Referenced by handle_action(), peek(), and vertical_move().

◆ vertical_notes()

void game::vertical_notes ( int  z_before,
int  z_after 
)

Add goes up/down auto_notes (if turned on)

Definition at line 10648 of file game.cpp.

10649{
10650 if( z_before == z_after || !get_option<bool>( "AUTO_NOTES" ) ||
10651 !get_option<bool>( "AUTO_NOTES_STAIRS" ) ) {
10652 return;
10653 }
10654
10655 if( !m.inbounds_z( z_before ) || !m.inbounds_z( z_after ) ) {
10656 debugmsg( "game::vertical_notes invalid arguments: z_before == %d, z_after == %d",
10657 z_before, z_after );
10658 return;
10659 }
10660 // Figure out where we know there are up/down connectors
10661 // Fill in all the tiles we know about (e.g. subway stations)
10662 static const int REVEAL_RADIUS = 40;
10663 for( const tripoint_abs_omt &p : points_in_radius( u.global_omt_location(), REVEAL_RADIUS ) ) {
10664 const tripoint_abs_omt cursp_before( p.xy(), z_before );
10665 const tripoint_abs_omt cursp_after( p.xy(), z_after );
10666
10667 if( !overmap_buffer.seen( cursp_before ) ) {
10668 continue;
10669 }
10670 if( overmap_buffer.has_note( cursp_after ) ) {
10671 // Already has a note -> never add an AUTO-note
10672 continue;
10673 }
10674 const oter_id &ter = overmap_buffer.ter( cursp_before );
10675 const oter_id &ter2 = overmap_buffer.ter( cursp_after );
10676 if( z_after > z_before && ter->has_flag( known_up ) &&
10677 !ter2->has_flag( known_down ) ) {
10678 overmap_buffer.set_seen( cursp_after, true );
10679 overmap_buffer.add_note( cursp_after, string_format( ">:W;%s", _( "AUTO: goes down" ) ) );
10680 } else if( z_after < z_before && ter->has_flag( known_down ) &&
10681 !ter2->has_flag( known_up ) ) {
10682 overmap_buffer.set_seen( cursp_after, true );
10683 overmap_buffer.add_note( cursp_after, string_format( "<:W;%s", _( "AUTO: goes up" ) ) );
10684 }
10685 }
10686}
bool inbounds_z(const int z) const
Definition: map.h:1628
void add_note(const tripoint_abs_omt &, const std::string &message)
@ known_up
Definition: omdata.h:87
@ known_down
Definition: omdata.h:86
bool has_flag(oter_flags flag) const
Definition: omdata.h:258

References _, overmapbuffer::add_note(), debugmsg, Character::global_omt_location(), oter_t::has_flag(), overmapbuffer::has_note(), map::inbounds_z(), known_down, known_up, m, overmap_buffer, points_in_radius(), overmapbuffer::seen(), overmapbuffer::set_seen(), string_format(), overmapbuffer::ter(), and u.

Referenced by vertical_shift().

◆ vertical_shift()

void game::vertical_shift ( int  z_after)

Actual z-level movement part of vertical_move.

Doesn't include stair finding, traps etc.

Definition at line 10611 of file game.cpp.

10612{
10613 if( z_after < -OVERMAP_DEPTH || z_after > OVERMAP_HEIGHT ) {
10614 debugmsg( "Tried to get z-level %d outside allowed range of %d-%d",
10615 z_after, -OVERMAP_DEPTH, OVERMAP_HEIGHT );
10616 return;
10617 }
10618
10619 // TODO: Implement dragging stuff up/down
10620 u.grab( OBJECT_NONE );
10621
10622 scent.reset();
10623
10624 u.setz( z_after );
10625 const int z_before = get_levz();
10626 if( !m.has_zlevels() ) {
10628 m.access_cache( z_before ).vehicle_list.clear();
10629 m.access_cache( z_before ).zone_vehicles.clear();
10630 m.access_cache( z_before ).map_memory_seen_cache.reset();
10631 m.set_transparency_cache_dirty( z_before );
10632 m.set_outside_cache_dirty( z_before );
10633 m.load( tripoint( get_levx(), get_levy(), z_after ), true );
10634 shift_monsters( tripoint( 0, 0, z_after - z_before ) );
10635 reload_npcs();
10636 } else {
10637 // Shift the map itself
10638 m.vertical_shift( z_after );
10639 }
10640
10641 m.spawn_monsters( true );
10642 // this may be required after a vertical shift if z-levels are not enabled
10643 // the critter is unloaded/loaded, and it needs to reconstruct its rider data after being reloaded.
10645 vertical_notes( z_before, z_after );
10646}
void setz(int z)
Definition: character.h:810
void vertical_notes(int z_before, int z_after)
Add goes up/down auto_notes (if turned on)
Definition: game.cpp:10648
void set_transparency_cache_dirty(const int zlev)
Sets a dirty flag on the a given cache.
Definition: map.cpp:201
void set_outside_cache_dirty(const int zlev)
Definition: map.cpp:222
void vertical_shift(int newz)
Moves the map vertically to (not by!) newz.
Definition: map.cpp:7050
std::set< vehicle * > zone_vehicles
Definition: map.h:358
std::set< vehicle * > vehicle_list
Definition: map.h:357

References map::access_cache(), map::clear_vehicle_cache(), debugmsg, get_levx(), get_levy(), get_levz(), avatar::grab(), map::has_zlevels(), map::load(), m, level_cache::map_memory_seen_cache, OBJECT_NONE, OVERMAP_DEPTH, OVERMAP_HEIGHT, reload_npcs(), scent_map::reset(), scent, map::set_outside_cache_dirty(), map::set_transparency_cache_dirty(), Character::setz(), shift_monsters(), map::spawn_monsters(), u, validate_mounted_npcs(), level_cache::vehicle_list, vertical_notes(), map::vertical_shift(), and level_cache::zone_vehicles.

Referenced by place_player(), and vertical_move().

◆ walk_move()

bool game::walk_move ( const tripoint dest,
bool  via_ramp = false 
)

TODO: This should really use the mounted creatures stamina, if mounted. Monsters don't currently have stamina however. For the time being just don't burn players stamina when mounted.

Dexterity decreases chance of tentacles getting stuck to the ground Intelligence decreases chance of tentacles getting stuck to the ground

Definition at line 8796 of file game.cpp.

8797{
8798 if( m.has_flag_ter( TFLAG_SMALL_PASSAGE, dest_loc ) ) {
8799 if( u.get_size() > MS_MEDIUM ) {
8800 add_msg( m_warning, _( "You can't fit there." ) );
8801 return false; // character too large to fit through a tight passage
8802 }
8803 if( u.is_mounted() ) {
8804 monster *mount = u.mounted_creature.get();
8805 if( mount->get_size() > MS_MEDIUM ) {
8806 add_msg( m_warning, _( "Your mount can't fit there." ) );
8807 return false; // char's mount is too large for tight passages
8808 }
8809 }
8810 }
8811
8812 if( u.is_mounted() ) {
8813 auto mons = u.mounted_creature.get();
8814 if( mons->has_flag( MF_RIDEABLE_MECH ) ) {
8815 if( !mons->check_mech_powered() ) {
8816 add_msg( m_bad, _( "Your %s refuses to move as its batteries have been drained." ),
8817 mons->get_name() );
8818 return false;
8819 }
8820 }
8821 if( !mons->move_effects( false ) ) {
8822 add_msg( m_bad, _( "You cannot move as your %s isn't able to move." ), mons->get_name() );
8823 return false;
8824 }
8825 }
8826 const optional_vpart_position vp_here = m.veh_at( u.pos() );
8827 const optional_vpart_position vp_there = m.veh_at( dest_loc );
8828
8829 bool pushing = false; // moving -into- grabbed tile; skip check for move_cost > 0
8830 bool pulling = false; // moving -away- from grabbed tile; check for move_cost > 0
8831 bool shifting_furniture = false; // moving furniture and staying still; skip check for move_cost > 0
8832
8833 const tripoint furn_pos = u.pos() + u.grab_point;
8834 const tripoint furn_dest = dest_loc + u.grab_point;
8835
8836 bool grabbed = u.get_grab_type() != OBJECT_NONE;
8837 if( grabbed ) {
8838 const tripoint dp = dest_loc - u.pos();
8839 pushing = dp == u.grab_point;
8840 pulling = dp == -u.grab_point;
8841 }
8842 if( grabbed && dest_loc.z != u.posz() ) {
8843 add_msg( m_warning, _( "You let go of the grabbed object." ) );
8844 grabbed = false;
8845 u.grab( OBJECT_NONE );
8846 }
8847
8848 // Now make sure we're actually holding something
8849 const vehicle *grabbed_vehicle = nullptr;
8850 if( grabbed && u.get_grab_type() == OBJECT_FURNITURE ) {
8851 // We only care about shifting, because it's the only one that can change our destination
8852 if( m.has_furn( u.pos() + u.grab_point ) ) {
8853 shifting_furniture = !pushing && !pulling;
8854 } else {
8855 // We were grabbing a furniture that isn't there
8856 grabbed = false;
8857 }
8858 } else if( grabbed && u.get_grab_type() == OBJECT_VEHICLE ) {
8859 grabbed_vehicle = veh_pointer_or_null( m.veh_at( u.pos() + u.grab_point ) );
8860 if( grabbed_vehicle == nullptr ) {
8861 // We were grabbing a vehicle that isn't there anymore
8862 grabbed = false;
8863 }
8864 } else if( grabbed ) {
8865 // We were grabbing something WEIRD, let's pretend we weren't
8866 grabbed = false;
8867 }
8868 if( u.grab_point != tripoint_zero && !grabbed ) {
8869 add_msg( m_warning, _( "Can't find grabbed object." ) );
8870 u.grab( OBJECT_NONE );
8871 }
8872
8873 if( m.impassable( dest_loc ) && !pushing && !shifting_furniture ) {
8874 if( vp_there && u.mounted_creature && u.mounted_creature->has_flag( MF_RIDEABLE_MECH ) &&
8875 vp_there->vehicle().handle_potential_theft( u ) ) {
8876 tripoint diff = dest_loc - u.pos();
8877 if( diff.x < 0 ) {
8878 diff.x -= 2;
8879 } else if( diff.x > 0 ) {
8880 diff.x += 2;
8881 }
8882 if( diff.y < 0 ) {
8883 diff.y -= 2;
8884 } else if( diff.y > 0 ) {
8885 diff.y += 2;
8886 }
8887 u.mounted_creature->shove_vehicle( dest_loc + diff.xy(),
8888 dest_loc );
8889 }
8890 return false;
8891 }
8892 if( vp_there && !vp_there->vehicle().handle_potential_theft( u ) ) {
8893 return false;
8894 }
8895 if( u.is_mounted() && !pushing && vp_there ) {
8896 add_msg( m_warning, _( "You cannot board a vehicle whilst riding." ) );
8897 return false;
8898 }
8899 u.set_underwater( false );
8900
8901 if( !shifting_furniture && !pushing && is_dangerous_tile( dest_loc ) ) {
8902 std::vector<std::string> harmful_stuff = get_dangerous_tile( dest_loc );
8903 const auto dangerous_terrain_opt = get_option<std::string>( "DANGEROUS_TERRAIN_WARNING_PROMPT" );
8904 const auto harmful_text = enumerate_as_string( harmful_stuff );
8905 const auto looks_risky = _( "Stepping into that %1$s looks risky. %2$s" );
8906
8907 const auto warn_msg = [&]( std::string_view action ) {
8908 add_msg( m_warning, looks_risky, harmful_text, action.data() );
8909 };
8910
8911 if( dangerous_terrain_opt == "IGNORE" ) {
8912 warn_msg( _( "But you enter anyway." ) );
8913 } else if( dangerous_terrain_opt == "ALWAYS" && !prompt_dangerous_tile( dest_loc ) ) {
8914 return true;
8915 } else if( dangerous_terrain_opt == "RUNNING" &&
8916 ( !u.movement_mode_is( CMM_RUN ) || !prompt_dangerous_tile( dest_loc ) ) ) {
8917 warn_msg( _( "Run into it if you wish to enter anyway." ) );
8918 return true;
8919 } else if( dangerous_terrain_opt == "CROUCHING" &&
8920 ( !u.movement_mode_is( CMM_CROUCH ) || !prompt_dangerous_tile( dest_loc ) ) ) {
8921 warn_msg( _( "Crouch and move into it if you wish to enter anyway." ) );
8922 return true;
8923 } else if( dangerous_terrain_opt == "NEVER" && !u.movement_mode_is( CMM_RUN ) ) {
8924 warn_msg( _( "Run into it if you wish to enter anyway." ) );
8925 return true;
8926 }
8927 }
8928 // Used to decide whether to print a 'moving is slow message
8929 const int mcost_from = m.move_cost( u.pos() ); //calculate this _before_ calling grabbed_move
8930
8931 int modifier = 0;
8932 if( grabbed && u.get_grab_type() == OBJECT_FURNITURE && u.pos() + u.grab_point == dest_loc ) {
8933 modifier = -m.furn( dest_loc ).obj().movecost;
8934 }
8935
8936 int multiplier = 1;
8937 if( u.is_on_ground() ) {
8938 multiplier *= 3;
8939 }
8940
8941 const int mcost = m.combined_movecost( u.pos(), dest_loc, grabbed_vehicle, modifier,
8942 via_ramp ) * multiplier;
8943 if( grabbed_move( dest_loc - u.pos() ) ) {
8944 return true;
8945 } else if( mcost == 0 ) {
8946 return false;
8947 }
8948 bool diag = trigdist && u.posx() != dest_loc.x && u.posy() != dest_loc.y;
8949 const int previous_moves = u.moves;
8950 if( u.is_mounted() ) {
8951 auto crit = u.mounted_creature.get();
8952 if( !crit->has_flag( MF_RIDEABLE_MECH ) &&
8953 ( m.has_flag_ter_or_furn( "MOUNTABLE", dest_loc ) ||
8954 m.has_flag_ter_or_furn( "BARRICADABLE_DOOR", dest_loc ) ||
8955 m.has_flag_ter_or_furn( "OPENCLOSE_INSIDE", dest_loc ) ||
8956 m.has_flag_ter_or_furn( "BARRICADABLE_DOOR_DAMAGED", dest_loc ) ||
8957 m.has_flag_ter_or_furn( "BARRICADABLE_DOOR_REINFORCED", dest_loc ) ) ) {
8958 add_msg( m_warning, _( "You cannot pass obstacles whilst mounted." ) );
8959 return false;
8960 }
8961 const double base_moves = u.run_cost( mcost, diag ) * 100.0 / crit->get_speed();
8962 const double encumb_moves = u.get_weight() / 4800.0_gram;
8963 u.moves -= static_cast<int>( std::ceil( base_moves + encumb_moves ) );
8964 if( u.movement_mode_is( CMM_WALK ) ) {
8965 crit->use_mech_power( -2 );
8966 } else if( u.movement_mode_is( CMM_CROUCH ) ) {
8967 crit->use_mech_power( -1 );
8968 } else if( u.movement_mode_is( CMM_RUN ) ) {
8969 crit->use_mech_power( -3 );
8970 }
8971 } else {
8972 u.moves -= u.run_cost( mcost, diag );
8973 /**
8974 TODO:
8975 This should really use the mounted creatures stamina, if mounted.
8976 Monsters don't currently have stamina however.
8977 For the time being just don't burn players stamina when mounted.
8978 */
8979 if( grabbed_vehicle == nullptr || grabbed_vehicle->wheelcache.empty() ) {
8980 //Burn normal amount of stamina if no vehicle grabbed or vehicle lacks wheels
8981 u.burn_move_stamina( previous_moves - u.moves );
8982 } else {
8983 //Burn half as much stamina if vehicle has wheels, without changing move time
8984 u.burn_move_stamina( 0.50 * ( previous_moves - u.moves ) );
8985 }
8986 }
8987 // Max out recoil & reset aim point
8989 u.last_target_pos = std::nullopt;
8990
8991 // Print a message if movement is slow
8992 const int mcost_to = m.move_cost( dest_loc ); //calculate this _after_ calling grabbed_move
8993 const bool fungus = m.has_flag_ter_or_furn( "FUNGUS", u.pos() ) ||
8994 m.has_flag_ter_or_furn( "FUNGUS",
8995 dest_loc ); //fungal furniture has no slowing effect on mycus characters
8996 const bool slowed = ( ( !u.has_trait( trait_PARKOUR ) && ( mcost_to > 2 || mcost_from > 2 ) ) ||
8997 mcost_to > 4 || mcost_from > 4 ) &&
8998 !( u.has_trait( trait_M_IMMUNE ) && fungus );
8999 if( slowed && !u.is_mounted() ) {
9000 // Unless u.pos() has a higher movecost than dest_loc, state that dest_loc is the cause
9001 if( mcost_to >= mcost_from ) {
9002 if( auto displayed_part = vp_there.part_displayed() ) {
9003 add_msg( m_warning, _( "Moving onto this %s is slow!" ),
9004 displayed_part->part().name() );
9005 sfx::do_obstacle( displayed_part->part().info().get_id().str() );
9006 } else {
9007 add_msg( m_warning, _( "Moving onto this %s is slow!" ), m.name( dest_loc ) );
9008 sfx::do_obstacle( m.ter( dest_loc ).id().str() );
9009 }
9010 } else {
9011 if( auto displayed_part = vp_here.part_displayed() ) {
9012 add_msg( m_warning, _( "Moving off of this %s is slow!" ),
9013 displayed_part->part().name() );
9014 sfx::do_obstacle( displayed_part->part().info().get_id().str() );
9015 } else {
9016 add_msg( m_warning, _( "Moving off of this %s is slow!" ), m.name( u.pos() ) );
9017 sfx::do_obstacle( m.ter( u.pos() ).id().str() );
9018 }
9019 }
9020 }
9021 if( !u.is_mounted() && u.has_trait( trait_id( "LEG_TENT_BRACE" ) ) &&
9022 ( !u.footwear_factor() ||
9023 ( u.footwear_factor() == .5 && one_in( 2 ) ) ) ) {
9024 // DX and IN are long suits for Cephalopods,
9025 // so this shouldn't cause too much hardship
9026 // Presumed that if it's swimmable, they're
9027 // swimming and won't stick
9028 ///\EFFECT_DEX decreases chance of tentacles getting stuck to the ground
9029
9030 ///\EFFECT_INT decreases chance of tentacles getting stuck to the ground
9031 if( !m.has_flag( "SWIMMABLE", dest_loc ) && one_in( 80 + u.dex_cur + u.int_cur ) ) {
9032 add_msg( _( "Your tentacles stick to the ground, but you pull them free." ) );
9033 u.mod_fatigue( 1 );
9034 }
9035 }
9036 if( !u.has_artifact_with( AEP_STEALTH ) && !u.has_trait( trait_id( "DEBUG_SILENT" ) ) ) {
9037 int volume = u.is_stealthy() ? 3 : 6;
9038 volume *= u.mutation_value( "noise_modifier" );
9039 if( volume > 0 ) {
9041 volume = 2;
9042 } else if( u.has_bionic( bionic_id( "bio_ankles" ) ) ) {
9043 volume = 12;
9044 }
9045 if( u.movement_mode_is( CMM_RUN ) ) {
9046 volume *= 1.5;
9047 } else if( u.movement_mode_is( CMM_CROUCH ) ) {
9048 volume /= 2;
9049 }
9050 if( u.is_mounted() ) {
9051 auto mons = u.mounted_creature.get();
9052 switch( mons->get_size() ) {
9053 case MS_TINY:
9054 volume = 0; // No sound for the tinies
9055 break;
9056 case MS_SMALL:
9057 volume /= 3;
9058 break;
9059 case MS_MEDIUM:
9060 break;
9061 case MS_LARGE:
9062 volume *= 1.5;
9063 break;
9064 case MS_HUGE:
9065 volume *= 2;
9066 break;
9067 default:
9068 break;
9069 }
9070 if( mons->has_flag( MF_LOUDMOVES ) ) {
9071 volume += 6;
9072 }
9073 sounds::sound( dest_loc, volume, sounds::sound_t::movement, mons->type->get_footsteps(), false,
9074 "none", "none" );
9075 } else {
9076 sounds::sound( dest_loc, volume, sounds::sound_t::movement, _( "footsteps" ), true,
9077 "none", "none" ); // Sound of footsteps may awaken nearby monsters
9078 }
9080 }
9081
9082 if( one_in( 20 ) && u.has_artifact_with( AEP_MOVEMENT_NOISE ) ) {
9083 sounds::sound( u.pos(), 40, sounds::sound_t::movement, _( "a rattling sound." ), true,
9084 "misc", "rattling" );
9085 }
9086 }
9087
9088 if( m.has_flag_ter_or_furn( TFLAG_HIDE_PLACE, dest_loc ) ) {
9089 add_msg( m_good, _( "You are hiding in the %s." ), m.name( dest_loc ) );
9090 }
9091
9092 if( dest_loc != u.pos() ) {
9094 }
9095
9096 tripoint oldpos = u.pos();
9097 point submap_shift = place_player( dest_loc );
9098 point ms_shift = sm_to_ms_copy( submap_shift );
9099 oldpos = oldpos - ms_shift;
9100
9101 if( pulling ) {
9102 const tripoint shifted_furn_pos = furn_pos - ms_shift;
9103 const tripoint shifted_furn_dest = furn_dest - ms_shift;
9104 const time_duration fire_age = m.get_field_age( shifted_furn_pos, fd_fire );
9105 const int fire_intensity = m.get_field_intensity( shifted_furn_pos, fd_fire );
9106 m.remove_field( shifted_furn_pos, fd_fire );
9107 m.set_field_intensity( shifted_furn_dest, fd_fire, fire_intensity );
9108 m.set_field_age( shifted_furn_dest, fd_fire, fire_age );
9109 }
9110
9111 if( u.is_hauling() ) {
9112 start_hauling( oldpos );
9113 }
9114
9116
9117 return true;
9118}
void burn_move_stamina(int moves)
Definition: character.cpp:7124
bool is_stealthy() const
Returns true if the player has stealthy movement.
virtual bool has_artifact_with(art_effect_passive effect) const
Definition: character.cpp:3213
units::mass get_weight() const override
Returns body weight plus weight of inventory and worn/wielded items.
Definition: character.cpp:3688
bool is_on_ground() const override
Returns true if the player is knocked over or has broken legs.
Definition: character.cpp:897
float mutation_value(const std::string &val) const
Goes over all mutations, gets min and max of a value with given name.
Definition: character.cpp:6650
int run_cost(int base_cost, bool diag=false) const
Returns the player's modified base movement cost.
m_size get_size() const override
Get size class of character.
Definition: character.cpp:575
bool grabbed_move(const tripoint &dp)
Check for dangerous stuff at dest_loc, return false if the player decides not to step there.
Definition: game.cpp:9731
bool is_dangerous_tile(const tripoint &dest_loc) const
Definition: game.cpp:8719
int combined_movecost(const tripoint &from, const tripoint &to, const vehicle *ignored_vehicle=nullptr, int modifier=0, bool flying=false, bool via_ramp=false) const
Cost to move out of one tile and into the next.
Definition: map.cpp:1903
m_size get_size() const override
Definition: monster.cpp:2734
std::optional< vpart_reference > part_displayed() const
Definition: vehicle.cpp:2500
std::optional< tripoint > last_target_pos
Definition: player.h:242
const std::string & str() const
Returns the identifier as plain std::string.
Definition: string_id.h:263
@ MS_TINY
Definition: creature.h:58
@ MS_LARGE
Definition: creature.h:61
@ MS_MEDIUM
Definition: creature.h:60
basic_string_view< char > string_view
Definition: fmtlib_core.h:465
static const itype_id itype_rm13_armor_on("rm13_armor_on")
static const trait_id trait_M_IMMUNE("M_IMMUNE")
@ TFLAG_SMALL_PASSAGE
Definition: mapdata.h:321
@ TFLAG_HIDE_PLACE
Definition: mapdata.h:316
@ MF_LOUDMOVES
Definition: mtype.h:176
void fungus(player &p, const tripoint &examp)
Remove furniture.
Definition: iexamine.cpp:2139
void do_obstacle(const std::string &obst="")
Definition: sounds.cpp:1634
void do_footstep()
Definition: sounds.cpp:1611

References _, action, add_msg(), AEP_MOVEMENT_NOISE, AEP_STEALTH, cata_event_dispatch::avatar_moves(), Character::burn_move_stamina(), CMM_CROUCH, CMM_RUN, CMM_WALK, map::combined_movecost(), Character::dex_cur, sfx::do_footstep(), sfx::do_obstacle(), enumerate_as_string(), fd_fire, Character::footwear_factor(), iexamine::fungus(), map::furn(), get_dangerous_tile(), map::get_field_age(), map::get_field_intensity(), avatar::get_grab_type(), Character::get_size(), monster::get_size(), Character::get_weight(), avatar::grab(), player::grab_point, grabbed_move(), Character::has_artifact_with(), Character::has_bionic(), map::has_flag(), map::has_flag_ter(), map::has_flag_ter_or_furn(), map::has_furn(), Character::has_trait(), int_id< T >::id(), map::impassable(), Character::int_cur, is_dangerous_tile(), Character::is_hauling(), Character::is_mounted(), Character::is_on_ground(), Character::is_stealthy(), Character::is_wearing(), itype_rm13_armor_on, player::last_target_pos, m, m_bad, m_good, m_warning, MAX_RECOIL, MF_LOUDMOVES, MF_RIDEABLE_MECH, Character::mod_fatigue(), Character::mounted_creature, map::move_cost(), map_data_common_t::movecost, sounds::movement, Character::movement_mode_is(), Creature::moves, MS_HUGE, MS_LARGE, MS_MEDIUM, MS_SMALL, MS_TINY, Character::mutation_value(), map::name(), int_id< T >::obj(), OBJECT_FURNITURE, OBJECT_NONE, OBJECT_VEHICLE, on_move_effects(), one_in(), optional_vpart_position::part_displayed(), place_player(), Character::pos(), Character::posx(), Character::posy(), Character::posz(), prompt_dangerous_tile(), Character::recoil, map::remove_field(), Character::run_cost(), map::set_field_age(), map::set_field_intensity(), Character::set_underwater(), sm_to_ms_copy(), sounds::sound(), start_hauling(), string_id< T >::str(), map::ter(), TFLAG_HIDE_PLACE, TFLAG_SMALL_PASSAGE, trait_M_IMMUNE, trait_PARKOUR, trigdist, tripoint_zero, u, map::veh_at(), veh_pointer_or_null(), vehicle::wheelcache, tripoint::x, tripoint::xy(), tripoint::y, and tripoint::z.

Referenced by swap_critters().

◆ win()

void game::win ( )

Marks the game as won.

Doesn't end the game.

Definition at line 2431 of file game.cpp.

2432{
2433 win_screen();
2435 memorial().add(
2436 pgettext( "memorial_male", "Closed the portal in %1$.1f days (%2$d seconds)." ),
2437 pgettext( "memorial_female", "Closed the portal in %1$.1f days (%2$d seconds)." ),
2438 to_days<float>( game_duration ), to_seconds<int>( game_duration ) );
2439 if( !u.is_dead_state() ) {
2442 }
2443}
void win_screen()
Definition: game.cpp:2445
void add(const std::string &male_msg, const std::string &female_msg)
Adds an event to the memorial log, to be written to the memorial file when the character dies.
const time_point & start_of_game
Definition: calendar.cpp:34

References achievements_tracker_ptr, memorial_logger::add(), Messages::display_messages(), get_kill_tracker(), Character::is_dead_state(), memorial(), pgettext(), show_scores_ui(), calendar::start_of_game, stats(), calendar::turn, u, and win_screen().

◆ win_screen()

void game::win_screen ( )
private

Definition at line 2445 of file game.cpp.

2446{
2447 // TODO: Move this wall somewhere
2449 std::string msg = _( "You managed to close the portal and end the invasion!" );
2450 msg += '\n';
2451 if( u.is_dead_state() ) {
2453 "Unfortunately, you had to sacrifice your life to achieve this." );
2454 msg += colorize( t, c_red ) + '\n';
2455 memorial().add(
2456 pgettext( "memorial_male", "Sacrificed his life to close the portal." ),
2457 pgettext( "memorial_female", "Sacrificed her life to close the portal." ) );
2458 } else {
2459 translation t = translation::to_translation( "win_game", "You managed to survive the ordeal." );
2460 msg += colorize( t, c_green ) + '\n';
2461 memorial().add(
2462 pgettext( "memorial_male", "Safely closed the portal." ),
2463 pgettext( "memorial_female", "Safely closed the portal." ) );
2464 }
2465 msg += string_format( _( "It took you %1$.1f days (%2$d seconds)." ),
2466 to_days<float>( game_duration ), to_seconds<int>( game_duration ) );
2467 // TODO: Print starting stats, traits, skills, all mods ever used, easiest of settings
2468 popup( msg );
2469}
Class for storing translation context and raw string for deferred translation.
Definition: translations.h:152
static translation to_translation(const std::string &raw)
Store a string, an optional plural form, and an optional context for translation.

References _, memorial_logger::add(), c_green, c_red, colorize(), Character::is_dead_state(), memorial(), pgettext(), popup(), calendar::start_of_game, string_format(), translation::to_translation(), calendar::turn, and u.

Referenced by win().

◆ write_memorial_file()

void game::write_memorial_file ( const std::string &  filename,
std::string  sLastWords 
)

Writes information about the character out to a text file timestamped with the time of the file was made.

This serves as a record of the character's state at the time the memorial was made (usually upon death) and accomplishments in a human-readable format.

Definition at line 2789 of file game.cpp.

2790{
2791 const std::string &memorial_dir = PATH_INFO::memorialdir();
2792 const std::string &memorial_active_world_dir = memorial_dir +
2793 world_generator->active_world->world_name + "/";
2794
2795 //Check if both dirs exist. Nested assure_dir_exist fails if the first dir of the nested dir does not exist.
2796 if( !assure_dir_exist( memorial_dir ) ) {
2797 debugmsg( "Could not make '%s' directory", memorial_dir );
2798 return;
2799 }
2800
2801 if( !assure_dir_exist( memorial_active_world_dir ) ) {
2802 debugmsg( "Could not make '%s' directory", memorial_active_world_dir );
2803 return;
2804 }
2805
2806 std::string path = memorial_active_world_dir + filename + ".txt";
2807
2808 write_to_file( path, [&]( std::ostream & fout ) {
2809 memorial().write( fout, sLastWords );
2810 }, _( "player memorial" ) );
2811}
void write(std::ostream &memorial_file, const std::string &epitaph) const
std::string memorialdir()
Definition: path_info.cpp:222

References _, assure_dir_exist(), debugmsg, memorial(), PATH_INFO::memorialdir(), world_generator, memorial_logger::write(), and write_to_file().

Referenced by cleanup_at_end().

◆ zones_manager()

void game::zones_manager ( )

Definition at line 6124 of file game.cpp.

6125{
6126 const tripoint stored_view_offset = u.view_offset;
6127
6129
6130 const int zone_ui_height = 12;
6131 const int zone_options_height = 7;
6132
6133 const int width = 45;
6134
6135 int offsetX = 0;
6136 int max_rows = 0;
6137
6138 catacurses::window w_zones;
6139 catacurses::window w_zones_border;
6140 catacurses::window w_zones_info;
6141 catacurses::window w_zones_info_border;
6142 catacurses::window w_zones_options;
6143
6144 bool show = true;
6145
6146 ui_adaptor ui;
6147 ui.on_screen_resize( [&]( ui_adaptor & ui ) {
6148 if( !show ) {
6149 ui.position( point_zero, point_zero );
6150 return;
6151 }
6152 offsetX = get_option<std::string>( "SIDEBAR_POSITION" ) != "left" ?
6153 TERMX - width : 0;
6154 const int w_zone_height = TERMY - zone_ui_height;
6155 max_rows = w_zone_height - 2;
6156 w_zones = catacurses::newwin( w_zone_height - 2, width - 2,
6157 point( offsetX + 1, 1 ) );
6158 w_zones_border = catacurses::newwin( w_zone_height, width,
6159 point( offsetX, 0 ) );
6160 w_zones_info = catacurses::newwin( zone_ui_height - zone_options_height - 1,
6161 width - 2, point( offsetX + 1, w_zone_height ) );
6162 w_zones_info_border = catacurses::newwin( zone_ui_height, width,
6163 point( offsetX, w_zone_height ) );
6164 w_zones_options = catacurses::newwin( zone_options_height - 1, width - 2,
6165 point( offsetX + 1, TERMY - zone_options_height ) );
6166
6167 ui.position( point( offsetX, 0 ), point( width, TERMY ) );
6168 } );
6169 ui.mark_resize();
6170
6171 std::string action;
6172 input_context ctxt( "ZONES_MANAGER" );
6173 ctxt.register_cardinal();
6174 ctxt.register_action( "CONFIRM" );
6175 ctxt.register_action( "QUIT" );
6176 ctxt.register_action( "ADD_ZONE" );
6177 ctxt.register_action( "REMOVE_ZONE" );
6178 ctxt.register_action( "MOVE_ZONE_UP" );
6179 ctxt.register_action( "MOVE_ZONE_DOWN" );
6180 ctxt.register_action( "SHOW_ZONE_ON_MAP" );
6181 ctxt.register_action( "ENABLE_ZONE" );
6182 ctxt.register_action( "DISABLE_ZONE" );
6183 ctxt.register_action( "SHOW_ALL_ZONES" );
6184 ctxt.register_action( "HELP_KEYBINDINGS" );
6185
6186 auto &mgr = zone_manager::get_manager();
6187 int start_index = 0;
6188 int active_index = 0;
6189 bool blink = false;
6190 bool stuff_changed = false;
6191 bool show_all_zones = false;
6192 int zone_cnt = 0;
6193
6194 // get zones on the same z-level, with distance between player and
6195 // zone center point <= 50 or all zones, if show_all_zones is true
6196 auto get_zones = [&]() {
6197 std::vector<zone_manager::ref_zone_data> zones;
6198 if( show_all_zones ) {
6199 zones = mgr.get_zones();
6200 } else {
6201 const tripoint &u_abs_pos = m.getabs( u.pos() );
6202 for( zone_manager::ref_zone_data &ref : mgr.get_zones() ) {
6203 const tripoint &zone_abs_pos = ref.get().get_center_point();
6204 if( u_abs_pos.z == zone_abs_pos.z && rl_dist( u_abs_pos, zone_abs_pos ) <= 50 ) {
6205 zones.emplace_back( ref );
6206 }
6207 }
6208 }
6209 zone_cnt = static_cast<int>( zones.size() );
6210 return zones;
6211 };
6212
6213 auto zones = get_zones();
6214
6215 auto zones_manager_options = [&]() {
6216 werase( w_zones_options );
6217
6218 if( zone_cnt > 0 ) {
6219 const auto &zone = zones[active_index].get();
6220
6221 if( zone.has_options() ) {
6222 const auto &descriptions = zone.get_options().get_descriptions();
6223
6224 // NOLINTNEXTLINE(cata-use-named-point-constants)
6225 mvwprintz( w_zones_options, point( 1, 0 ), c_white, _( "Options" ) );
6226
6227 int y = 1;
6228 for( const auto &desc : descriptions ) {
6229 mvwprintz( w_zones_options, point( 3, y ), c_white, desc.first );
6230 mvwprintz( w_zones_options, point( 20, y ), c_white, desc.second );
6231 y++;
6232 }
6233 }
6234 }
6235
6236 wnoutrefresh( w_zones_options );
6237 };
6238
6239 std::optional<tripoint> zone_start;
6240 std::optional<tripoint> zone_end;
6241 bool zone_blink = false;
6242 bool zone_cursor = false;
6244 zone_start, zone_end, zone_blink, zone_cursor );
6245 add_draw_callback( zone_cb );
6246
6247 auto query_position =
6248 [&]() -> std::optional<std::pair<tripoint, tripoint>> {
6249 on_out_of_scope invalidate_current_ui( [&]()
6250 {
6251 ui.mark_resize();
6252 } );
6253 restore_on_out_of_scope<bool> show_prev( show );
6254 restore_on_out_of_scope<std::optional<tripoint>> zone_start_prev( zone_start );
6255 restore_on_out_of_scope<std::optional<tripoint>> zone_end_prev( zone_end );
6256 show = false;
6257 zone_start = std::nullopt;
6258 zone_end = std::nullopt;
6259 ui.mark_resize();
6260
6262 popup.on_top( true );
6263 popup.message( "%s", _( "Select first point." ) );
6264
6266
6267 const look_around_result first = look_around( /*show_window=*/false, center, center, false, true,
6268 false );
6269 if( first.position )
6270 {
6271 popup.message( "%s", _( "Select second point." ) );
6272
6273 const look_around_result second = look_around( /*show_window=*/false, center, *first.position,
6274 true, true, false );
6275 if( second.position ) {
6276 tripoint first_abs = m.getabs( tripoint( std::min( first.position->x,
6277 second.position->x ),
6278 std::min( first.position->y, second.position->y ),
6279 std::min( first.position->z,
6280 second.position->z ) ) );
6281 tripoint second_abs = m.getabs( tripoint( std::max( first.position->x,
6282 second.position->x ),
6283 std::max( first.position->y, second.position->y ),
6284 std::max( first.position->z,
6285 second.position->z ) ) );
6286 return std::pair<tripoint, tripoint>( first_abs, second_abs );
6287 }
6288 }
6289
6290 return std::nullopt;
6291 };
6292
6293 ui.on_redraw( [&]( const ui_adaptor & ) {
6294 if( !show ) {
6295 return;
6296 }
6297 zones_manager_draw_borders( w_zones_border, w_zones_info_border, zone_ui_height, width );
6298 zones_manager_shortcuts( w_zones_info );
6299
6300 if( zone_cnt == 0 ) {
6301 werase( w_zones );
6302 mvwprintz( w_zones, point( 2, 5 ), c_white, _( "No Zones defined." ) );
6303
6304 } else {
6305 werase( w_zones );
6306
6307 calcStartPos( start_index, active_index, max_rows, zone_cnt );
6308
6309 draw_scrollbar( w_zones_border, active_index, max_rows, zone_cnt, point_south );
6310 wnoutrefresh( w_zones_border );
6311
6312 int iNum = 0;
6313
6314 tripoint player_absolute_pos = m.getabs( u.pos() );
6315
6316 //Display saved zones
6317 for( auto &i : zones ) {
6318 if( iNum >= start_index &&
6319 iNum < start_index + ( ( max_rows > zone_cnt ) ? zone_cnt : max_rows ) ) {
6320 const auto &zone = i.get();
6321
6322 nc_color colorLine = ( zone.get_enabled() ) ? c_white : c_light_gray;
6323
6324 if( iNum == active_index ) {
6325 mvwprintz( w_zones, point( 0, iNum - start_index ), c_yellow, "%s", ">>" );
6326 colorLine = ( zone.get_enabled() ) ? c_light_green : c_green;
6327 }
6328
6329 //Draw Zone name
6330 mvwprintz( w_zones, point( 3, iNum - start_index ), colorLine,
6331 trim_by_length( zone.get_name(), 15 ) );
6332
6333 //Draw Type name
6334 mvwprintz( w_zones, point( 20, iNum - start_index ), colorLine,
6335 mgr.get_name_from_type( zone.get_type() ) );
6336
6337 tripoint center = zone.get_center_point();
6338
6339 //Draw direction + distance
6340 mvwprintz( w_zones, point( 32, iNum - start_index ), colorLine, "%*d %s",
6341 5, static_cast<int>( trig_dist( player_absolute_pos, center ) ),
6342 direction_name_short( direction_from( player_absolute_pos,
6343 center ) ) );
6344
6345 //Draw Vehicle Indicator
6346 mvwprintz( w_zones, point( 41, iNum - start_index ), colorLine,
6347 zone.get_is_vehicle() ? "*" : "" );
6348 }
6349 iNum++;
6350 }
6351
6352 // Display zone options
6353 zones_manager_options();
6354 }
6355
6356 wnoutrefresh( w_zones );
6357 } );
6358
6359 zones_manager_open = true;
6360 do {
6361 if( action == "ADD_ZONE" ) {
6362 do { // not a loop, just for quick bailing out if canceled
6363 const auto maybe_id = mgr.query_type();
6364 if( !maybe_id.has_value() ) {
6365 break;
6366 }
6367
6368 const zone_type_id &id = maybe_id.value();
6369 auto options = zone_options::create( id );
6370
6371 if( !options->query_at_creation() ) {
6372 break;
6373 }
6374
6375 auto default_name = options->get_zone_name_suggestion();
6376 if( default_name.empty() ) {
6377 default_name = mgr.get_name_from_type( id );
6378 }
6379 const auto maybe_name = mgr.query_name( default_name );
6380 if( !maybe_name.has_value() ) {
6381 break;
6382 }
6383 const std::string &name = maybe_name.value();
6384
6385 const auto position = query_position();
6386 if( !position ) {
6387 break;
6388 }
6389
6390 mgr.add( name, id, g->u.get_faction()->id, false, true, position->first,
6391 position->second, options );
6392
6393 zones = get_zones();
6394 active_index = zone_cnt - 1;
6395
6396 stuff_changed = true;
6397 } while( false );
6398
6399 blink = false;
6400 } else if( action == "SHOW_ALL_ZONES" ) {
6401 show_all_zones = !show_all_zones;
6402 zones = get_zones();
6403 active_index = 0;
6404 } else if( zone_cnt > 0 ) {
6405 if( action == "UP" ) {
6406 active_index--;
6407 if( active_index < 0 ) {
6408 active_index = zone_cnt - 1;
6409 }
6410 blink = false;
6411 } else if( action == "DOWN" ) {
6412 active_index++;
6413 if( active_index >= zone_cnt ) {
6414 active_index = 0;
6415 }
6416 blink = false;
6417 } else if( action == "REMOVE_ZONE" ) {
6418 if( active_index < zone_cnt ) {
6419 mgr.remove( zones[active_index] );
6420 zones = get_zones();
6421 active_index--;
6422
6423 if( active_index < 0 ) {
6424 active_index = 0;
6425 }
6426 }
6427 blink = false;
6428 stuff_changed = true;
6429
6430 } else if( action == "CONFIRM" ) {
6431 auto &zone = zones[active_index].get();
6432
6433 uilist as_m;
6434 as_m.text = _( "What do you want to change:" );
6435 as_m.entries.emplace_back( 1, true, '1', _( "Edit name" ) );
6436 as_m.entries.emplace_back( 2, true, '2', _( "Edit type" ) );
6437 as_m.entries.emplace_back( 3, zone.get_options().has_options(), '3',
6438 zone.get_type() == zone_type_id( "LOOT_CUSTOM" ) ? _( "Edit filter" ) : _( "Edit options" ) );
6439 as_m.entries.emplace_back( 4, !zone.get_is_vehicle(), '4', _( "Edit position" ) );
6440 // TODO: Enable moving vzone after vehicle zone can be bigger than 1*1
6441 as_m.entries.emplace_back( 5, !zone.get_is_vehicle(), '5', _( "Move position" ) );
6442 as_m.query();
6443
6444 switch( as_m.ret ) {
6445 case 1:
6446 if( zone.set_name() ) {
6447 stuff_changed = true;
6448 }
6449 break;
6450 case 2:
6451 if( zone.set_type() ) {
6452 stuff_changed = true;
6453 }
6454 break;
6455 case 3:
6456 if( zone.get_options().query() ) {
6457 stuff_changed = true;
6458 }
6459 break;
6460 case 4: {
6461 const auto pos = query_position();
6462 if( pos && ( pos->first != zone.get_start_point() ||
6463 pos->second != zone.get_end_point() ) ) {
6464 zone.set_position( *pos );
6465 stuff_changed = true;
6466 }
6467 break;
6468 }
6469 case 5: {
6470 on_out_of_scope invalidate_current_ui( [&]() {
6471 ui.mark_resize();
6472 } );
6473 restore_on_out_of_scope<bool> show_prev( show );
6474 restore_on_out_of_scope<std::optional<tripoint>> zone_start_prev( zone_start );
6475 restore_on_out_of_scope<std::optional<tripoint>> zone_end_prev( zone_end );
6476 show = false;
6477 zone_start = std::nullopt;
6478 zone_end = std::nullopt;
6479 ui.mark_resize();
6480 static_popup message_pop;
6481 message_pop.on_top( true );
6482 message_pop.message( "%s", _( "Moving zone." ) );
6483 const auto zone_local_start_point = m.getlocal( zone.get_start_point() );
6484 const auto zone_local_end_point = m.getlocal( zone.get_end_point() );
6485 // local position of the zone center, used to calculate the u.view_offset,
6486 // could center the screen to the position it represents
6487 auto view_center = m.getlocal( zone.get_center_point() );
6488 const look_around_result result_local = look_around( false, view_center,
6489 zone_local_start_point, false, false,
6490 false, true, zone_local_end_point );
6491 if( result_local.position ) {
6492 const auto new_start_point = m.getabs( *result_local.position );
6493 if( new_start_point == zone.get_start_point() ) {
6494 break; // Nothing changed, don't save
6495 }
6496
6497 const auto new_end_point = zone.get_end_point() - zone.get_start_point() + new_start_point;
6498 zone.set_position( std::pair<tripoint, tripoint>( new_start_point, new_end_point ) );
6499 stuff_changed = true;
6500 }
6501 }
6502 break;
6503 default:
6504 break;
6505 }
6506
6507 blink = false;
6508 } else if( action == "MOVE_ZONE_UP" && zone_cnt > 1 ) {
6509 if( active_index < zone_cnt - 1 ) {
6510 mgr.swap( zones[active_index], zones[active_index + 1] );
6511 zones = get_zones();
6512 active_index++;
6513 }
6514 blink = false;
6515 stuff_changed = true;
6516
6517 } else if( action == "MOVE_ZONE_DOWN" && zone_cnt > 1 ) {
6518 if( active_index > 0 ) {
6519 mgr.swap( zones[active_index], zones[active_index - 1] );
6520 zones = get_zones();
6521 active_index--;
6522 }
6523 blink = false;
6524 stuff_changed = true;
6525
6526 } else if( action == "SHOW_ZONE_ON_MAP" ) {
6527 //show zone position on overmap;
6528 tripoint_abs_omt player_overmap_position = u.global_omt_location();
6529 // TODO: fix point types
6530 tripoint_abs_omt zone_overmap( ms_to_omt_copy( zones[active_index].get().get_center_point() ) );
6531
6532 ui::omap::display_zones( player_overmap_position, zone_overmap, active_index );
6533 } else if( action == "ENABLE_ZONE" ) {
6534 zones[active_index].get().set_enabled( true );
6535
6536 stuff_changed = true;
6537
6538 } else if( action == "DISABLE_ZONE" ) {
6539 zones[active_index].get().set_enabled( false );
6540
6541 stuff_changed = true;
6542 }
6543 }
6544
6545 if( zone_cnt > 0 ) {
6546 blink = !blink;
6547 const auto &zone = zones[active_index].get();
6548 zone_start = m.getlocal( zone.get_start_point() );
6549 zone_end = m.getlocal( zone.get_end_point() );
6550 ctxt.set_timeout( get_option<int>( "BLINK_SPEED" ) );
6551 } else {
6552 blink = false;
6553 zone_start = zone_end = std::nullopt;
6554 ctxt.reset_timeout();
6555 }
6556
6557 // Actually accessed from the terrain overlay callback `zone_cb` in the
6558 // call to `ui_manager::redraw`.
6559 //NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores)
6560 zone_blink = blink;
6562
6564
6565 //Wait for input
6566 action = ctxt.handle_input();
6567 } while( action != "QUIT" );
6568 zones_manager_open = false;
6569 ctxt.reset_timeout();
6570 zone_cb = nullptr;
6571
6572 if( stuff_changed ) {
6573 auto &zones = zone_manager::get_manager();
6574 if( query_yn( _( "Save changes?" ) ) ) {
6575 zones.save_zones();
6576 } else {
6577 zones.load_zones();
6578 }
6579
6580 zones.cache_data();
6581 }
6582
6583 u.view_offset = stored_view_offset;
6584}
query_popup & on_top(bool top)
Whether to show the popup on the top of the screen.
Definition: popup.cpp:59
std::reference_wrapper< zone_data > ref_zone_data
Definition: clzones.h:342
static shared_ptr_fast< zone_options > create(const zone_type_id &type)
Definition: clzones.cpp:187
int trig_dist(const coords::coord_point< Point, Origin, Scale > &loc1, const coords::coord_point< Point, Origin, Scale > &loc2)
Definition: coordinates.h:512
static void zones_manager_shortcuts(const catacurses::window &w_info)
Definition: game.cpp:6059
static void zones_manager_draw_borders(const catacurses::window &w_border, const catacurses::window &w_info_border, const int iInfoHeight, const int width)
Definition: game.cpp:6082
void optional(const JsonObject &jo, const bool was_loaded, const std::string &name, MemberType &member)
std::string options()
Definition: path_info.cpp:230
const std::set< itype_id > & get()
void display_zones(const tripoint_abs_omt &center, const tripoint_abs_omt &select, int iZoneIndex)
Display overmap like with display() and display the given zone.
std::string trim_by_length(const std::string &text, int width)
Definition: output.cpp:224
std::optional< tripoint > position
Definition: game.h:127

References _, action, add_draw_callback(), c_green, c_light_gray, c_light_green, c_white, c_yellow, calcStartPos(), center, zone_options::create(), create_zone_callback(), direction_from(), direction_name_short(), ui::omap::display_zones(), draw_scrollbar(), uilist::entries, g, charge_removal_blacklist::get(), zone_manager::get_manager(), map::getabs(), map::getlocal(), Character::global_omt_location(), input_context::handle_input(), invalidate_main_ui_adaptor(), look_around(), m, query_popup::message(), ms_to_omt_copy(), mvwprintz(), om_direction::name(), catacurses::newwin(), query_popup::on_top(), optional(), PATH_INFO::options(), point_south, point_zero, popup(), Character::pos(), look_around_result::position, uilist::query(), query_yn(), ui_manager::redraw(), input_context::register_action(), input_context::register_cardinal(), input_context::reset_timeout(), uilist::ret, rl_dist(), second, input_context::set_timeout(), TERMX, TERMY, uilist::text, trig_dist(), trim_by_length(), tripoint_zero, u, player::view_offset, catacurses::werase(), catacurses::wnoutrefresh(), tripoint::z, zones_manager_draw_borders(), zones_manager_open, and zones_manager_shortcuts().

Referenced by handle_action().

◆ zoom_in()

void game::zoom_in ( )

Definition at line 7086 of file game.cpp.

7087{
7088#if defined(TILES)
7089 if( tileset_zoom == 64 ) {
7090 tileset_zoom = MAXIMUM_ZOOM_LEVEL;
7091 } else {
7093 }
7094 rescale_tileset( tileset_zoom );
7095#endif
7096}

References tileset_zoom.

Referenced by handle_action(), and look_around().

◆ zoom_out()

void game::zoom_out ( )

Definition at line 7074 of file game.cpp.

7075{
7076#if defined(TILES)
7077 if( tileset_zoom > MAXIMUM_ZOOM_LEVEL ) {
7079 } else {
7080 tileset_zoom = 64;
7081 }
7082 rescale_tileset( tileset_zoom );
7083#endif
7084}

References tileset_zoom.

Referenced by handle_action(), and look_around().

Friends And Related Function Documentation

◆ advanced_inventory

friend class advanced_inventory
friend

Definition at line 146 of file game.h.

◆ Creature_range

friend class Creature_range
friend

Definition at line 334 of file game.h.

Referenced by all_creatures().

◆ editmap

friend class editmap
friend

Definition at line 145 of file game.h.

◆ get_avatar

avatar & get_avatar ( )
friend

Definition at line 105 of file avatar.cpp.

106{
107 return g->u;
108}

Referenced by butcher_submenu(), and get_player_base_save_path().

◆ get_distribution_grid_tracker

distribution_grid_tracker & get_distribution_grid_tracker ( )
friend

Returns distribution grid tracker that is a part of the global game *g.

game TODO: This wouldn't be required in an ideal world

Definition at line 12116 of file game.cpp.

12117{
12118 return *g->grid_tracker_ptr;
12119}

◆ get_map

map & get_map ( )
friend

◆ get_player_character

Character & get_player_character ( )
friend

Definition at line 402 of file character.cpp.

403{
404 return g->u;
405}

◆ get_weather

weather_manager & get_weather ( )
friend

Definition at line 64 of file weather.cpp.

65{
66 return *g->weather_manager_ptr;
67}

Referenced by do_turn(), get_player_input(), is_in_sunlight(), load(), natural_light_level(), place_player_overmap(), serialize_master(), setup(), start_game(), and unserialize_master().

◆ main_menu

friend class main_menu
friend

Definition at line 147 of file game.h.

◆ monster_range

friend class monster_range
friend

Definition at line 333 of file game.h.

Referenced by all_monsters().

Member Data Documentation

◆ achievements_tracker_ptr

pimpl<achievements_tracker> game::achievements_tracker_ptr
private

Definition at line 954 of file game.h.

Referenced by death_screen(), game(), handle_action(), serialize(), setup(), unserialize(), and win().

◆ active_npc

◆ auto_travel_mode

bool game::auto_travel_mode = false

Definition at line 1017 of file game.h.

Referenced by handle_action(), serialize(), and unserialize().

◆ bVMonsterLookFire

bool game::bVMonsterLookFire = false
private

Definition at line 1034 of file game.h.

Referenced by list_monsters(), look_around(), and setup().

◆ coming_to_stairs

std::vector<monster> game::coming_to_stairs

◆ critter_died

bool game::critter_died = false
private

Has anything died in this turn and needs to be cleaned up?

Definition at line 1048 of file game.h.

Referenced by cleanup_dead(), and set_critter_died().

◆ critter_tracker

◆ debug_hour_timer

◆ debug_pathfinding

bool game::debug_pathfinding = false

Definition at line 998 of file game.h.

◆ debug_submap_grid_overlay

bool game::debug_submap_grid_overlay = false

Definition at line 999 of file game.h.

◆ destination_preview

std::vector<tripoint> game::destination_preview
private

◆ displaying_lighting_condition

int game::displaying_lighting_condition = 0

Type of lighting condition overlay to display.

Definition at line 1011 of file game.h.

◆ displaying_overlays

std::optional<action_id> game::displaying_overlays
private

Definition at line 917 of file game.h.

Referenced by display_overlay_state(), and display_toggle_overlay().

◆ displaying_visibility_creature

Creature* game::displaying_visibility_creature

Creature for which to display the visibility map.

Definition at line 1009 of file game.h.

Referenced by display_visibility().

◆ draw_callbacks

std::vector<weak_ptr_fast<draw_callback_t> > game::draw_callbacks
private

Definition at line 225 of file game.h.

Referenced by add_draw_callback(), and draw().

◆ driving_view_offset

point game::driving_view_offset

Definition at line 996 of file game.h.

Referenced by calc_driving_offset(), do_turn(), handle_action(), and set_driving_view_offset().

◆ event_bus_ptr

pimpl<event_bus> game::event_bus_ptr
private

Definition at line 951 of file game.h.

Referenced by events().

◆ faction_manager_ptr

◆ first_redraw_since_waiting_started

bool game::first_redraw_since_waiting_started = true
private

Is this the first redraw since waiting (sleeping or activity) started.

Definition at line 1050 of file game.h.

Referenced by do_turn(), and game().

◆ follower_ids

std::set<character_id> game::follower_ids
private

◆ fullscreen

bool game::fullscreen = false

◆ gamemode

std::unique_ptr<special_game> game::gamemode
private

◆ grid_tracker_ptr

pimpl<distribution_grid_tracker> game::grid_tracker_ptr
private

Definition at line 957 of file game.h.

Referenced by do_turn(), load_map(), on_options_changed(), and update_map().

◆ is_looking

bool game::is_looking = false
private

Definition at line 224 of file game.h.

Referenced by draw_ter(), and look_around().

◆ kill_tracker_ptr

pimpl<kill_tracker> game::kill_tracker_ptr
private

Definition at line 953 of file game.h.

Referenced by game(), get_kill_tracker(), serialize(), and unserialize().

◆ last_mouse_edge_scroll

std::chrono::time_point<std::chrono::steady_clock> game::last_mouse_edge_scroll
private

Definition at line 1067 of file game.h.

Referenced by mouse_edge_scrolling().

◆ last_mouse_edge_scroll_vector_overmap

tripoint game::last_mouse_edge_scroll_vector_overmap
private

Definition at line 1069 of file game.h.

Referenced by mouse_edge_scrolling_overmap(), and mouse_edge_scrolling_terrain().

◆ last_mouse_edge_scroll_vector_terrain

tripoint game::last_mouse_edge_scroll_vector_terrain
private

Definition at line 1068 of file game.h.

Referenced by mouse_edge_scrolling_overmap(), and mouse_edge_scrolling_terrain().

◆ last_save_timestamp

time_t game::last_save_timestamp
private

Definition at line 1040 of file game.h.

Referenced by autosave(), init_autosave(), and quicksave().

◆ latest_lightlevels

std::array<float, OVERMAP_LAYERS> game::latest_lightlevels
mutableprivate

Definition at line 1041 of file game.h.

Referenced by natural_light_level(), and reset_light_level().

◆ list_item_downvote

std::string game::list_item_downvote
private

Definition at line 1031 of file game.h.

Referenced by list_items().

◆ list_item_upvote

std::string game::list_item_upvote
private

Definition at line 1030 of file game.h.

Referenced by list_items().

◆ liveview

live_view& game::liveview
private

Definition at line 948 of file game.h.

Referenced by draw_look_around_cursor(), and handle_mouseview().

◆ liveview_ptr

pimpl<live_view> game::liveview_ptr
private

Definition at line 947 of file game.h.

◆ m

map& game::m

Definition at line 961 of file game.h.

Referenced by autopilot_vehicles(), cata_event_dispatch::avatar_moves(), butcher(), catch_a_monster(), chat(), check_near_zone(), check_zone(), control_vehicle(), delete_cyborg_item(), disable_robot(), disp_NPCs(), do_turn(), draw(), draw_bullet(), draw_critter(), draw_critter_highlighted(), draw_critter_internal(), draw_hit_mon(), draw_look_around_cursor(), draw_ter(), examine(), extended_description(), find_nearby_items(), find_or_make_stairs(), fling_creature(), forced_door_closing(), get_cur_om(), get_dangerous_tile(), get_fishable_locations(), get_levx(), get_levy(), get_levz(), get_player_input(), get_veh_dir_indicator_location(), grabbed_furn_move(), grabbed_veh_move(), handle_action(), is_empty(), is_game_over(), is_in_sunlight(), is_sheltered(), knockback(), list_items(), list_monsters(), load(), load_map(), load_npcs(), look_around(), mon_info_update(), monmove(), moving_vehicle_dismount(), peek(), perhaps_add_random_npc(), phasing_move(), pickup(), place_critter_around(), place_player(), place_player_overmap(), place_vehicle_nearby(), pre_print_all_tile_info(), print_all_tile_info(), print_fields_info(), print_graffiti_info(), print_items_info(), print_terrain_info(), print_trap_info(), process_artifact(), prompt_dangerous_tile(), remoteveh(), save_maps(), serialize(), setup(), shift_monsters(), start_game(), start_hauling(), swap_critters(), try_get_left_click_action(), try_get_right_click_action(), update_map(), update_stair_monsters(), use_computer(), validate_camps(), validate_linked_vehicles(), validate_mounted_npcs(), vertical_move(), vertical_notes(), vertical_shift(), walk_move(), and zones_manager().

◆ main_ui_adaptor

weak_ptr_fast<ui_adaptor> game::main_ui_adaptor
private

◆ map_ptr

pimpl<map> game::map_ptr
private

Definition at line 945 of file game.h.

◆ memorial_logger_ptr

pimpl<memorial_logger> game::memorial_logger_ptr
private

Definition at line 955 of file game.h.

Referenced by game(), and memorial().

◆ monstairz

int game::monstairz = 0

Definition at line 983 of file game.h.

Referenced by update_stair_monsters(), and vertical_move().

◆ mostseen

int game::mostseen = 0

◆ moves_since_last_save

int game::moves_since_last_save = 0
private

Definition at line 1039 of file game.h.

Referenced by do_turn(), get_moves_since_last_save(), init_autosave(), quickload(), and quicksave().

◆ new_game

bool game::new_game = false

True if the game has just started or loaded, else false.

Definition at line 979 of file game.h.

Referenced by do_turn(), setup(), and start_game().

◆ next_mission_id

int game::next_mission_id = 0
private

Definition at line 1037 of file game.h.

Referenced by assign_mission_id(), serialize_master(), setup(), and unserialize_master().

◆ next_npc_id

character_id game::next_npc_id
private

Definition at line 1035 of file game.h.

Referenced by assign_npc_id(), serialize_master(), setup(), and unserialize_master().

◆ npcs_dirty

bool game::npcs_dirty = false
private

Has a NPC been spawned since last load?

Definition at line 1046 of file game.h.

Referenced by do_turn(), load_npcs(), and set_npcs_dirty().

◆ queue_screenshot

bool game::queue_screenshot = false

Definition at line 1018 of file game.h.

Referenced by do_turn().

◆ remoteveh_cache

vehicle* game::remoteveh_cache
private

Definition at line 1044 of file game.h.

Referenced by remoteveh(), setremoteveh(), and setup().

◆ remoteveh_cache_time

time_point game::remoteveh_cache_time
private

Definition at line 1043 of file game.h.

Referenced by remoteveh(), setremoteveh(), and setup().

◆ right_sidebar

bool game::right_sidebar = false

Definition at line 1014 of file game.h.

◆ safe_mode

◆ safe_mode_warning_logged

bool game::safe_mode_warning_logged = false
private

Definition at line 1033 of file game.h.

Referenced by check_safe_mode_allowed(), handle_action(), and set_safe_mode().

◆ scen

const scenario* game::scen = nullptr

Definition at line 981 of file game.h.

Referenced by start_calendar(), and start_game().

◆ scent

scent_map& game::scent

Definition at line 963 of file game.h.

Referenced by display_scent(), do_turn(), serialize(), setup(), unserialize(), update_map(), and vertical_shift().

◆ scent_ptr

pimpl<scent_map> game::scent_ptr
private

Definition at line 949 of file game.h.

◆ seed

unsigned int game::seed = 0
private

Seed for all the random numbers that should have consistent randomness (weather).

Definition at line 1062 of file game.h.

Referenced by get_seed(), serialize_master(), start_game(), and unserialize_master().

◆ sFilter

std::string game::sFilter
private

Definition at line 1029 of file game.h.

Referenced by list_items(), and reset_item_list_state().

◆ show_panel_adm

bool game::show_panel_adm = false

Definition at line 1013 of file game.h.

Referenced by draw_panels(), and load_static_data().

◆ spell_events_ptr

pimpl<spell_events> game::spell_events_ptr
private

Definition at line 956 of file game.h.

Referenced by game(), and spell_events_subscriber().

◆ stats_tracker_ptr

pimpl<stats_tracker> game::stats_tracker_ptr
private

Definition at line 952 of file game.h.

Referenced by game(), serialize(), stats(), and unserialize().

◆ ter_view_p

tripoint game::ter_view_p

Definition at line 985 of file game.h.

Referenced by draw(), and draw_ter().

◆ tileset_zoom

int game::tileset_zoom = 0
private

How far the tileset should be zoomed out, 16 is default.

32 is zoomed in by x2, 8 is zoomed out by x0.5

Definition at line 1059 of file game.h.

Referenced by get_zoom(), look_around(), mouse_edge_scrolling_terrain(), reset_zoom(), set_zoom(), zoom_in(), and zoom_out().

◆ timed_event_manager_ptr

pimpl<timed_event_manager> game::timed_event_manager_ptr
private

Definition at line 950 of file game.h.

◆ timed_events

timed_event_manager& game::timed_events

Definition at line 964 of file game.h.

Referenced by do_turn(), natural_light_level(), and setup().

◆ token_provider_ptr

pimpl<drop_token_provider> game::token_provider_ptr

Definition at line 974 of file game.h.

Referenced by serialize(), setup(), and unserialize().

◆ turnssincelastmon

int game::turnssincelastmon = 0

Definition at line 1020 of file game.h.

Referenced by handle_action(), mon_info_update(), and setup().

◆ u

avatar& game::u

Definition at line 962 of file game.h.

Referenced by add_artifact_dreams(), add_npc_follower(), autopilot_vehicles(), cata_event_dispatch::avatar_moves(), butcher(), calc_driving_offset(), cancel_activity_or_ignore_query(), cancel_activity_query(), catch_a_monster(), centerlistview(), chat(), check_safe_mode_allowed(), cleanup_at_end(), control_vehicle(), create_starting_npcs(), critter_at(), critter_by_id(), death_screen(), disable_robot(), disp_NPCs(), display_scent(), do_turn(), draw(), draw_critter(), draw_critter_highlighted(), draw_critter_internal(), draw_hit_mon(), draw_line(), draw_look_around_cursor(), draw_minimap(), draw_panels(), draw_ter(), draw_trail_to_square(), draw_veh_dir_indicator(), drop(), drop_in_direction(), exam_vehicle(), examine(), extended_description(), find_nearby_items(), find_or_make_stairs(), fling_creature(), forced_door_closing(), fungal_effects::fungalize(), get_dangerous_tile(), get_player_input(), get_veh_dir_indicator_location(), grabbed_furn_move(), grabbed_move(), grabbed_veh_move(), handle_action(), handle_key_blocking_activity(), inv_map_splice(), is_game_over(), is_hostile_within(), is_in_viewport(), item_action_menu(), knockback(), list_items(), list_items_monsters(), list_missions(), list_monsters(), load(), look_around(), mon_info(), mon_info_update(), monmove(), move_save_to_graveyard(), moving_vehicle_dismount(), npc_menu(), on_move_effects(), open_consume_item_menu(), overmap_npc_move(), peek(), perhaps_add_random_npc(), phasing_move(), pickup_feet(), place_player(), place_player_overmap(), print_all_tile_info(), print_creature_info(), print_items_info(), print_terrain_info(), print_trap_info(), process_activity(), process_artifact(), process_voluntary_act_interrupt(), prompt_dangerous_tile(), quickload(), remoteveh(), remove_npc_follower(), save(), save_player_data(), serialize(), set_driving_view_offset(), setremoteveh(), shared_from(), slip_down(), fungal_effects::spread_fungus_one_tile(), start_game(), start_hauling(), toggle_gate(), try_get_left_click_action(), try_get_right_click_action(), unserialize(), update_map(), update_overmap_seen(), update_stair_monsters(), use_computer(), validate_camps(), validate_npc_followers(), vertical_move(), vertical_notes(), vertical_shift(), walk_move(), win(), win_screen(), and zones_manager().

◆ u_ptr

pimpl<avatar> game::u_ptr
private

Definition at line 946 of file game.h.

◆ u_shared_ptr

shared_ptr_fast<player> game::u_shared_ptr
private

Definition at line 1024 of file game.h.

Referenced by shared_from().

◆ uquit

quit_status game::uquit

Used in main.cpp to determine what type of quit is being performed.

Definition at line 977 of file game.h.

Referenced by cleanup_at_end(), do_turn(), get_player_input(), handle_action(), is_game_over(), and setup().

◆ user_action_counter

int game::user_action_counter = 0
private

Definition at line 1056 of file game.h.

Referenced by get_user_action_counter(), and handle_action().

◆ w_minimap

catacurses::window game::w_minimap

Definition at line 989 of file game.h.

Referenced by create_or_get_main_ui_adaptor(), and draw_minimap().

◆ w_minimap_ptr

catacurses::window game::w_minimap_ptr
private

Definition at line 1027 of file game.h.

Referenced by create_or_get_main_ui_adaptor().

◆ w_omlegend

catacurses::window game::w_omlegend

Definition at line 988 of file game.h.

◆ w_overmap

catacurses::window game::w_overmap

Definition at line 987 of file game.h.

◆ w_pixel_minimap

catacurses::window game::w_pixel_minimap

◆ w_terrain

◆ w_terrain_ptr

catacurses::window game::w_terrain_ptr
private

Definition at line 1026 of file game.h.

Referenced by create_or_get_main_ui_adaptor().

◆ wait_popup

std::unique_ptr<static_popup> game::wait_popup
private

Definition at line 1075 of file game.h.

Referenced by do_turn().

◆ was_fullscreen

bool game::was_fullscreen = false

Definition at line 1016 of file game.h.

Referenced by load_static_data(), reenter_fullscreen(), and temp_exit_fullscreen().

◆ weather_manager_ptr

pimpl<weather_manager> game::weather_manager_ptr
private

Definition at line 958 of file game.h.

◆ zones_manager_open

bool game::zones_manager_open = false
private

Is Zone manager open or not - changes graphics of some zone tiles.

Definition at line 1052 of file game.h.

Referenced by is_zones_manager_open(), and zones_manager().


The documentation for this class was generated from the following files: